Skip to content

Commit 97bf824

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

File tree

4 files changed

+110
-67
lines changed

4 files changed

+110
-67
lines changed

Diff for: Classes/Controller/ModuleController.php

+17-35
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;
@@ -16,8 +19,8 @@
1619
use TYPO3\CMS\Core\Utility\GeneralUtility;
1720
use TYPO3\CMS\Extbase\Http\ForwardResponse;
1821
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
19-
use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
2022
use TYPO3\CMS\Extbase\Object\Exception;
23+
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
2124
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
2225
use TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException;
2326

@@ -26,7 +29,6 @@
2629
*/
2730
class ModuleController extends AbstractController
2831
{
29-
3032
/**
3133
* @param string $forwardToAction
3234
* @throws StopActionException
@@ -50,23 +52,13 @@ public function listAction(): ResponseInterface
5052
$formUids = $this->mailRepository->findGroupedFormUidsToGivenPageUid((int)$this->id);
5153
$mails = $this->mailRepository->findAllInPid((int)$this->id, $this->settings, $this->piVars);
5254

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-
);
55+
$currentPage = 1;
56+
if ($this->request->hasArgument('currentPage')) {
57+
$currentPage = $this->request->getArgument('currentPage');
58+
}
59+
$itemsPerPage = $this->settings['perPage'] ?? 10;
60+
$paginator = GeneralUtility::makeInstance(QueryResultPaginator::class, $mails, $currentPage, $itemsPerPage);
61+
$pagination = GeneralUtility::makeInstance(SlidingWindowPagination::class, $paginator, 15);
7062

7163
$firstFormUid = StringUtility::conditionalVariable($this->piVars['filter']['form'] ?? '', key($formUids));
7264
$beUser = BackendUtility::getBackendUserAuthentication();
@@ -82,7 +74,7 @@ public function listAction(): ResponseInterface
8274
'pagination' => $pagination,
8375
'paginator' => $paginator
8476
],
85-
'perPage' => ($this->settings['perPage'] ? $this->settings['perPage'] : 10),
77+
'perPage' => $this->settings['perPage'] ?? 10,
8678
'writeAccess' => $beUser->check('tables_modify', Answer::TABLE_NAME)
8779
&& $beUser->check('tables_modify', Mail::TABLE_NAME),
8880
]
@@ -209,21 +201,17 @@ public function overviewBeAction(): ResponseInterface
209201

210202
/**
211203
* @return void
212-
* @throws StopActionException
213-
* @noinspection PhpUnused
214204
*/
215205
public function initializeCheckBeAction(): void
216206
{
217207
$this->checkAdminPermissions();
218208
}
219209

220210
/**
221-
* @param string $email email address
222-
* @return void
223-
* @throws Exception
224-
* @noinspection PhpUnused
211+
* @param string|null $email
212+
* @return ResponseInterface
225213
*/
226-
public function checkBeAction($email = null): ResponseInterface
214+
public function checkBeAction(string $email = null): ResponseInterface
227215
{
228216
$this->view->assign('pid', $this->id);
229217
$this->sendTestEmail($email);
@@ -233,7 +221,6 @@ public function checkBeAction($email = null): ResponseInterface
233221
/**
234222
* @param null $email
235223
* @return void
236-
* @throws Exception
237224
*/
238225
protected function sendTestEmail($email = null): void
239226
{
@@ -252,7 +239,6 @@ protected function sendTestEmail($email = null): void
252239

253240
/**
254241
* @return void
255-
* @throws StopActionException
256242
* @noinspection PhpUnused
257243
*/
258244
public function initializeConverterBeAction(): void
@@ -262,7 +248,6 @@ public function initializeConverterBeAction(): void
262248

263249
/**
264250
* @return void
265-
* @throws StopActionException
266251
* @noinspection PhpUnused
267252
*/
268253
public function initializeFixUploadFolderAction(): void
@@ -273,8 +258,7 @@ public function initializeFixUploadFolderAction(): void
273258
/**
274259
* @return void
275260
* @throws StopActionException
276-
* @throws UnsupportedRequestTypeException
277-
* @throws \Exception
261+
* @throws FileCannotBeCreatedException
278262
* @noinspection PhpUnused
279263
*/
280264
public function fixUploadFolderAction(): void
@@ -285,7 +269,6 @@ public function fixUploadFolderAction(): void
285269

286270
/**
287271
* @return void
288-
* @throws StopActionException
289272
* @noinspection PhpUnused
290273
*/
291274
public function initializeFixWrongLocalizedFormsAction(): void
@@ -296,7 +279,7 @@ public function initializeFixWrongLocalizedFormsAction(): void
296279
/**
297280
* @return void
298281
* @throws StopActionException
299-
* @throws UnsupportedRequestTypeException
282+
* @throws DBALException
300283
* @noinspection PhpUnused
301284
*/
302285
public function fixWrongLocalizedFormsAction(): void
@@ -307,7 +290,6 @@ public function fixWrongLocalizedFormsAction(): void
307290

308291
/**
309292
* @return void
310-
* @throws StopActionException
311293
* @noinspection PhpUnused
312294
*/
313295
public function initializeFixWrongLocalizedPagesAction(): void

Diff for: Classes/Domain/Factory/FileFactory.php

+4-4
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
}

Diff for: Classes/Domain/Model/File.php

+16-14
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)