Skip to content

Commit

Permalink
[TASK] Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Jun 16, 2022
1 parent 06126ed commit 97bf824
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 67 deletions.
52 changes: 17 additions & 35 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
declare(strict_types = 1);
namespace In2code\Powermail\Controller;

use Doctrine\DBAL\DBALException;
use In2code\Powermail\Domain\Model\Answer;
use In2code\Powermail\Domain\Model\Mail;
use In2code\Powermail\Domain\Repository\PageRepository;
use In2code\Powermail\Domain\Service\SlidingWindowPagination;
use In2code\Powermail\Exception\FileCannotBeCreatedException;
use In2code\Powermail\Utility\BackendUtility;
use In2code\Powermail\Utility\BasicFileUtility;
use In2code\Powermail\Utility\ConfigurationUtility;
Expand All @@ -16,8 +19,8 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException;

Expand All @@ -26,7 +29,6 @@
*/
class ModuleController extends AbstractController
{

/**
* @param string $forwardToAction
* @throws StopActionException
Expand All @@ -50,23 +52,13 @@ public function listAction(): ResponseInterface
$formUids = $this->mailRepository->findGroupedFormUidsToGivenPageUid((int)$this->id);
$mails = $this->mailRepository->findAllInPid((int)$this->id, $this->settings, $this->piVars);

$currentPage = $this->request->hasArgument('currentPage')
? (int)$this->request->getArgument('currentPage')
: 1;

$itemsPerPage = (int)$this->settings['perPage'] ? (int)$this->settings['perPage'] : 10;
$maximumLinks = 15;

// Pagination for Mails
$paginator = new \TYPO3\CMS\Extbase\Pagination\QueryResultPaginator(
$mails,
$currentPage,
$itemsPerPage
);
$pagination = new \In2code\Powermail\Utility\SlidingWindowPagination(
$paginator,
$maximumLinks
);
$currentPage = 1;
if ($this->request->hasArgument('currentPage')) {
$currentPage = $this->request->getArgument('currentPage');
}
$itemsPerPage = $this->settings['perPage'] ?? 10;
$paginator = GeneralUtility::makeInstance(QueryResultPaginator::class, $mails, $currentPage, $itemsPerPage);
$pagination = GeneralUtility::makeInstance(SlidingWindowPagination::class, $paginator, 15);

$firstFormUid = StringUtility::conditionalVariable($this->piVars['filter']['form'] ?? '', key($formUids));
$beUser = BackendUtility::getBackendUserAuthentication();
Expand All @@ -82,7 +74,7 @@ public function listAction(): ResponseInterface
'pagination' => $pagination,
'paginator' => $paginator
],
'perPage' => ($this->settings['perPage'] ? $this->settings['perPage'] : 10),
'perPage' => $this->settings['perPage'] ?? 10,
'writeAccess' => $beUser->check('tables_modify', Answer::TABLE_NAME)
&& $beUser->check('tables_modify', Mail::TABLE_NAME),
]
Expand Down Expand Up @@ -209,21 +201,17 @@ public function overviewBeAction(): ResponseInterface

/**
* @return void
* @throws StopActionException
* @noinspection PhpUnused
*/
public function initializeCheckBeAction(): void
{
$this->checkAdminPermissions();
}

/**
* @param string $email email address
* @return void
* @throws Exception
* @noinspection PhpUnused
* @param string|null $email
* @return ResponseInterface
*/
public function checkBeAction($email = null): ResponseInterface
public function checkBeAction(string $email = null): ResponseInterface
{
$this->view->assign('pid', $this->id);
$this->sendTestEmail($email);
Expand All @@ -233,7 +221,6 @@ public function checkBeAction($email = null): ResponseInterface
/**
* @param null $email
* @return void
* @throws Exception
*/
protected function sendTestEmail($email = null): void
{
Expand All @@ -252,7 +239,6 @@ protected function sendTestEmail($email = null): void

/**
* @return void
* @throws StopActionException
* @noinspection PhpUnused
*/
public function initializeConverterBeAction(): void
Expand All @@ -262,7 +248,6 @@ public function initializeConverterBeAction(): void

/**
* @return void
* @throws StopActionException
* @noinspection PhpUnused
*/
public function initializeFixUploadFolderAction(): void
Expand All @@ -273,8 +258,7 @@ public function initializeFixUploadFolderAction(): void
/**
* @return void
* @throws StopActionException
* @throws UnsupportedRequestTypeException
* @throws \Exception
* @throws FileCannotBeCreatedException
* @noinspection PhpUnused
*/
public function fixUploadFolderAction(): void
Expand All @@ -285,7 +269,6 @@ public function fixUploadFolderAction(): void

/**
* @return void
* @throws StopActionException
* @noinspection PhpUnused
*/
public function initializeFixWrongLocalizedFormsAction(): void
Expand All @@ -296,7 +279,7 @@ public function initializeFixWrongLocalizedFormsAction(): void
/**
* @return void
* @throws StopActionException
* @throws UnsupportedRequestTypeException
* @throws DBALException
* @noinspection PhpUnused
*/
public function fixWrongLocalizedFormsAction(): void
Expand All @@ -307,7 +290,6 @@ public function fixWrongLocalizedFormsAction(): void

/**
* @return void
* @throws StopActionException
* @noinspection PhpUnused
*/
public function initializeFixWrongLocalizedPagesAction(): void
Expand Down
8 changes: 4 additions & 4 deletions Classes/Domain/Factory/FileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function __construct(array $settings)
*/
public function getInstanceFromFilesArray(array $filesArray, string $marker, int $key): ?File
{
$originalName = (string)$filesArray['name']['field'][$marker][$key];
$size = (int)$filesArray['size']['field'][$marker][$key];
$type = (string)$filesArray['type']['field'][$marker][$key];
$temporaryName = (string)$filesArray['tmp_name']['field'][$marker][$key];
$originalName = $filesArray['name']['field'][$marker][$key] ?? '';
$size = $filesArray['size']['field'][$marker][$key] ?? 0;
$type = $filesArray['type']['field'][$marker][$key] ?? '';
$temporaryName = $filesArray['tmp_name']['field'][$marker][$key] ?? '';
if (!empty($originalName) && !empty($temporaryName) && $size > 0) {
return $this->makeFileInstance($marker, $originalName, $size, $type, $temporaryName);
}
Expand Down
30 changes: 16 additions & 14 deletions Classes/Domain/Model/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,77 +21,77 @@ class File
*
* @var string
*/
protected $marker = '';
protected string $marker = '';

/**
* Original name
*
* @var string
*/
protected $originalName = '';
protected string $originalName = '';

/**
* Temporary uploaded name
*
* @var string|null
*/
protected $temporaryName = null;
protected ?string $temporaryName = null;

/**
* New, cleaned and unique filename
*
* @var string
*/
protected $newName = '';
protected string $newName = '';

/**
* Is there a problem with this file?
*
* @var bool
*/
protected $valid = true;
protected bool $valid = true;

/**
* Like "image/png"
*
* @var string
*/
protected $type = '';
protected string $type = '';

/**
* Filesize
*
* @var int
*/
protected $size = 0;
protected int $size = 0;

/**
* Uploadfolder for this file
*
* @var string
*/
protected $uploadFolder = 'uploads/tx_powermail/';
protected string $uploadFolder = 'uploads/tx_powermail/';

/**
* Already uploaded to uploadfolder?
*
* @var bool
*/
protected $uploaded = false;
protected bool $uploaded = false;

/**
* File must be renamed?
*
* @var bool
*/
protected $renamed = false;
protected bool $renamed = false;

/**
* Related field
*
* @var Field|null
*/
protected $field = null;
protected ?Field $field = null;

/**
* @param string $marker
Expand Down Expand Up @@ -134,8 +134,9 @@ public function getOriginalName(): string
/**
* @param string $originalName
* @return File
* @noinspection PhpUnused
*/
public function setOriginalName($originalName): File
public function setOriginalName(string $originalName): File
{
$this->originalName = $originalName;
return $this;
Expand All @@ -152,6 +153,7 @@ public function getTemporaryName(): string
/**
* @param string $temporaryName
* @return File
* @noinspection PhpUnused
*/
public function setTemporaryName(string $temporaryName): File
{
Expand Down Expand Up @@ -344,10 +346,10 @@ public function isFileExisting(): bool
* @throws InvalidSlotReturnException
* @throws Exception
*/
public function getNewPathAndFilename($absolute = false): string
public function getNewPathAndFilename(bool $absolute = false): string
{
$pathAndFilename = $this->getUploadFolder() . $this->getNewName();
if ($absolute) {
if ($absolute === true) {
$pathAndFilename = GeneralUtility::getFileAbsFileName($pathAndFilename);
}
$this->signalDispatch(__CLASS__, __FUNCTION__, [$pathAndFilename, $this]);
Expand Down
Loading

0 comments on commit 97bf824

Please sign in to comment.