Skip to content

Commit d7b250b

Browse files
committed
[TASK] Code cleanup
1 parent 06126ed commit d7b250b

File tree

4 files changed

+114
-69
lines changed

4 files changed

+114
-69
lines changed

Classes/Controller/ModuleController.php

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
declare(strict_types = 1);
33
namespace In2code\Powermail\Controller;
44

5+
use Doctrine\DBAL\DBALException;
56
use In2code\Powermail\Domain\Model\Answer;
67
use In2code\Powermail\Domain\Model\Mail;
78
use In2code\Powermail\Domain\Repository\PageRepository;
9+
use In2code\Powermail\Domain\Service\SlidingWindowPagination;
10+
use In2code\Powermail\Exception\FileCannotBeCreatedException;
811
use In2code\Powermail\Utility\BackendUtility;
912
use In2code\Powermail\Utility\BasicFileUtility;
1013
use In2code\Powermail\Utility\ConfigurationUtility;
@@ -15,9 +18,10 @@
1518
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
1619
use TYPO3\CMS\Core\Utility\GeneralUtility;
1720
use TYPO3\CMS\Extbase\Http\ForwardResponse;
21+
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
1822
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
19-
use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
2023
use TYPO3\CMS\Extbase\Object\Exception;
24+
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
2125
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
2226
use TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException;
2327

@@ -26,47 +30,37 @@
2630
*/
2731
class ModuleController extends AbstractController
2832
{
29-
3033
/**
3134
* @param string $forwardToAction
3235
* @throws StopActionException
3336
* @return void
3437
* @noinspection PhpUnused
3538
*/
36-
public function dispatchAction($forwardToAction = 'list'): ResponseInterface
39+
public function dispatchAction(string $forwardToAction = 'list'): ResponseInterface
3740
{
3841
$this->forward($forwardToAction);
3942
return $this->htmlResponse();
4043
}
4144

4245
/**
43-
* @return void
46+
* @return ResponseInterface
4447
* @throws InvalidQueryException
4548
* @throws RouteNotFoundException
49+
* @throws NoSuchArgumentException
4650
* @noinspection PhpUnused
4751
*/
4852
public function listAction(): ResponseInterface
4953
{
5054
$formUids = $this->mailRepository->findGroupedFormUidsToGivenPageUid((int)$this->id);
5155
$mails = $this->mailRepository->findAllInPid((int)$this->id, $this->settings, $this->piVars);
5256

53-
$currentPage = $this->request->hasArgument('currentPage')
54-
? (int)$this->request->getArgument('currentPage')
55-
: 1;
56-
57-
$itemsPerPage = (int)$this->settings['perPage'] ? (int)$this->settings['perPage'] : 10;
58-
$maximumLinks = 15;
59-
60-
// Pagination for Mails
61-
$paginator = new \TYPO3\CMS\Extbase\Pagination\QueryResultPaginator(
62-
$mails,
63-
$currentPage,
64-
$itemsPerPage
65-
);
66-
$pagination = new \In2code\Powermail\Utility\SlidingWindowPagination(
67-
$paginator,
68-
$maximumLinks
69-
);
57+
$currentPage = 1;
58+
if ($this->request->hasArgument('currentPage')) {
59+
$currentPage = $this->request->getArgument('currentPage');
60+
}
61+
$itemsPerPage = $this->settings['perPage'] ?? 10;
62+
$paginator = GeneralUtility::makeInstance(QueryResultPaginator::class, $mails, $currentPage, $itemsPerPage);
63+
$pagination = GeneralUtility::makeInstance(SlidingWindowPagination::class, $paginator, 15);
7064

7165
$firstFormUid = StringUtility::conditionalVariable($this->piVars['filter']['form'] ?? '', key($formUids));
7266
$beUser = BackendUtility::getBackendUserAuthentication();
@@ -82,7 +76,7 @@ public function listAction(): ResponseInterface
8276
'pagination' => $pagination,
8377
'paginator' => $paginator
8478
],
85-
'perPage' => ($this->settings['perPage'] ? $this->settings['perPage'] : 10),
79+
'perPage' => $this->settings['perPage'] ?? 10,
8680
'writeAccess' => $beUser->check('tables_modify', Answer::TABLE_NAME)
8781
&& $beUser->check('tables_modify', Mail::TABLE_NAME),
8882
]
@@ -209,21 +203,17 @@ public function overviewBeAction(): ResponseInterface
209203

210204
/**
211205
* @return void
212-
* @throws StopActionException
213-
* @noinspection PhpUnused
214206
*/
215207
public function initializeCheckBeAction(): void
216208
{
217209
$this->checkAdminPermissions();
218210
}
219211

220212
/**
221-
* @param string $email email address
222-
* @return void
223-
* @throws Exception
224-
* @noinspection PhpUnused
213+
* @param string|null $email
214+
* @return ResponseInterface
225215
*/
226-
public function checkBeAction($email = null): ResponseInterface
216+
public function checkBeAction(string $email = null): ResponseInterface
227217
{
228218
$this->view->assign('pid', $this->id);
229219
$this->sendTestEmail($email);
@@ -233,7 +223,6 @@ public function checkBeAction($email = null): ResponseInterface
233223
/**
234224
* @param null $email
235225
* @return void
236-
* @throws Exception
237226
*/
238227
protected function sendTestEmail($email = null): void
239228
{
@@ -252,7 +241,6 @@ protected function sendTestEmail($email = null): void
252241

253242
/**
254243
* @return void
255-
* @throws StopActionException
256244
* @noinspection PhpUnused
257245
*/
258246
public function initializeConverterBeAction(): void
@@ -262,7 +250,6 @@ public function initializeConverterBeAction(): void
262250

263251
/**
264252
* @return void
265-
* @throws StopActionException
266253
* @noinspection PhpUnused
267254
*/
268255
public function initializeFixUploadFolderAction(): void
@@ -273,8 +260,7 @@ public function initializeFixUploadFolderAction(): void
273260
/**
274261
* @return void
275262
* @throws StopActionException
276-
* @throws UnsupportedRequestTypeException
277-
* @throws \Exception
263+
* @throws FileCannotBeCreatedException
278264
* @noinspection PhpUnused
279265
*/
280266
public function fixUploadFolderAction(): void
@@ -285,7 +271,6 @@ public function fixUploadFolderAction(): void
285271

286272
/**
287273
* @return void
288-
* @throws StopActionException
289274
* @noinspection PhpUnused
290275
*/
291276
public function initializeFixWrongLocalizedFormsAction(): void
@@ -296,7 +281,7 @@ public function initializeFixWrongLocalizedFormsAction(): void
296281
/**
297282
* @return void
298283
* @throws StopActionException
299-
* @throws UnsupportedRequestTypeException
284+
* @throws DBALException
300285
* @noinspection PhpUnused
301286
*/
302287
public function fixWrongLocalizedFormsAction(): void
@@ -307,7 +292,6 @@ public function fixWrongLocalizedFormsAction(): void
307292

308293
/**
309294
* @return void
310-
* @throws StopActionException
311295
* @noinspection PhpUnused
312296
*/
313297
public function initializeFixWrongLocalizedPagesAction(): void

Classes/Domain/Factory/FileFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public function __construct(array $settings)
5252
*/
5353
public function getInstanceFromFilesArray(array $filesArray, string $marker, int $key): ?File
5454
{
55-
$originalName = (string)$filesArray['name']['field'][$marker][$key];
56-
$size = (int)$filesArray['size']['field'][$marker][$key];
57-
$type = (string)$filesArray['type']['field'][$marker][$key];
58-
$temporaryName = (string)$filesArray['tmp_name']['field'][$marker][$key];
55+
$originalName = $filesArray['name']['field'][$marker][$key] ?? '';
56+
$size = $filesArray['size']['field'][$marker][$key] ?? 0;
57+
$type = $filesArray['type']['field'][$marker][$key] ?? '';
58+
$temporaryName = $filesArray['tmp_name']['field'][$marker][$key] ?? '';
5959
if (!empty($originalName) && !empty($temporaryName) && $size > 0) {
6060
return $this->makeFileInstance($marker, $originalName, $size, $type, $temporaryName);
6161
}

Classes/Domain/Model/File.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,77 +21,77 @@ class File
2121
*
2222
* @var string
2323
*/
24-
protected $marker = '';
24+
protected string $marker = '';
2525

2626
/**
2727
* Original name
2828
*
2929
* @var string
3030
*/
31-
protected $originalName = '';
31+
protected string $originalName = '';
3232

3333
/**
3434
* Temporary uploaded name
3535
*
3636
* @var string|null
3737
*/
38-
protected $temporaryName = null;
38+
protected ?string $temporaryName = null;
3939

4040
/**
4141
* New, cleaned and unique filename
4242
*
4343
* @var string
4444
*/
45-
protected $newName = '';
45+
protected string $newName = '';
4646

4747
/**
4848
* Is there a problem with this file?
4949
*
5050
* @var bool
5151
*/
52-
protected $valid = true;
52+
protected bool $valid = true;
5353

5454
/**
5555
* Like "image/png"
5656
*
5757
* @var string
5858
*/
59-
protected $type = '';
59+
protected string $type = '';
6060

6161
/**
6262
* Filesize
6363
*
6464
* @var int
6565
*/
66-
protected $size = 0;
66+
protected int $size = 0;
6767

6868
/**
6969
* Uploadfolder for this file
7070
*
7171
* @var string
7272
*/
73-
protected $uploadFolder = 'uploads/tx_powermail/';
73+
protected string $uploadFolder = 'uploads/tx_powermail/';
7474

7575
/**
7676
* Already uploaded to uploadfolder?
7777
*
7878
* @var bool
7979
*/
80-
protected $uploaded = false;
80+
protected bool $uploaded = false;
8181

8282
/**
8383
* File must be renamed?
8484
*
8585
* @var bool
8686
*/
87-
protected $renamed = false;
87+
protected bool $renamed = false;
8888

8989
/**
9090
* Related field
9191
*
9292
* @var Field|null
9393
*/
94-
protected $field = null;
94+
protected ?Field $field = null;
9595

9696
/**
9797
* @param string $marker
@@ -134,8 +134,9 @@ public function getOriginalName(): string
134134
/**
135135
* @param string $originalName
136136
* @return File
137+
* @noinspection PhpUnused
137138
*/
138-
public function setOriginalName($originalName): File
139+
public function setOriginalName(string $originalName): File
139140
{
140141
$this->originalName = $originalName;
141142
return $this;
@@ -152,6 +153,7 @@ public function getTemporaryName(): string
152153
/**
153154
* @param string $temporaryName
154155
* @return File
156+
* @noinspection PhpUnused
155157
*/
156158
public function setTemporaryName(string $temporaryName): File
157159
{
@@ -344,10 +346,10 @@ public function isFileExisting(): bool
344346
* @throws InvalidSlotReturnException
345347
* @throws Exception
346348
*/
347-
public function getNewPathAndFilename($absolute = false): string
349+
public function getNewPathAndFilename(bool $absolute = false): string
348350
{
349351
$pathAndFilename = $this->getUploadFolder() . $this->getNewName();
350-
if ($absolute) {
352+
if ($absolute === true) {
351353
$pathAndFilename = GeneralUtility::getFileAbsFileName($pathAndFilename);
352354
}
353355
$this->signalDispatch(__CLASS__, __FUNCTION__, [$pathAndFilename, $this]);

0 commit comments

Comments
 (0)