From 7c78ff6a5dbb80190c0aec34df1e4bf77a7f79ea Mon Sep 17 00:00:00 2001 From: Lina Wolf <48202465+linawolf@users.noreply.github.com> Date: Sat, 4 May 2024 16:52:27 +0200 Subject: [PATCH] [TASK] Raise PHPstan level to 8 (#271) --- Build/phpstan/phpstan.neon | 2 +- Classes/Controller/ModuleController.php | 39 +++++++++++++------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Build/phpstan/phpstan.neon b/Build/phpstan/phpstan.neon index 1ada5b5..3d50062 100644 --- a/Build/phpstan/phpstan.neon +++ b/Build/phpstan/phpstan.neon @@ -3,7 +3,7 @@ includes: parameters: phpVersion: 80200 - level: 7 + level: 8 bootstrapFiles: - phpstan-typo3-constants.php diff --git a/Classes/Controller/ModuleController.php b/Classes/Controller/ModuleController.php index 48a23d5..33918ff 100644 --- a/Classes/Controller/ModuleController.php +++ b/Classes/Controller/ModuleController.php @@ -17,8 +17,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerAwareInterface; -use Psr\Log\LoggerAwareTrait; +use Psr\Log\LoggerInterface; use T3docs\Examples\Service\TableInformationService; use TYPO3\CMS\Backend\Clipboard\Clipboard; use TYPO3\CMS\Backend\Routing\UriBuilder; @@ -50,10 +49,8 @@ * * @author Francois Suter (Cobweb) */ -class ModuleController extends ActionController implements LoggerAwareInterface +class ModuleController extends ActionController { - use LoggerAwareTrait; - private int $pageUid; /** @var array */ private array $exampleConfig; @@ -68,6 +65,7 @@ public function __construct( protected readonly ConnectionPool $connectionPool, protected readonly DataHandler $dataHandler, protected readonly TableInformationService $tableInformationService, + private readonly LoggerInterface $logger, ) {} /** @@ -429,19 +427,22 @@ public function fileReferenceAction(int $element = 0): ResponseInterface * @param int $element Uid of the content element */ public function fileReferenceCreateAction( - $file, - $element, + int $file, + int $element, ): ResponseInterface { // Early return if either item is missing - if ((int)$file === 0 || (int)$element === 0) { + if ($file === 0 || $element === 0) { // NOTE: there would normally a nice error Flash Message added here $this->redirect('fileReference'); } - $fileObject = $this->resourceFactory->getFileObject((int)$file); + $fileObject = $this->resourceFactory->getFileObject($file); $contentElement = BackendUtility::getRecord( 'tt_content', - (int)$element, + $element, ); + if ($contentElement === null) { + throw new \Exception('Content element with uid ' . $element . ' not found'); + } // Assemble DataHandler data $newId = 'NEW1234'; $data = []; @@ -465,7 +466,7 @@ public function fileReferenceCreateAction( LocalizationUtility::translate( 'create_relation_success', 'examples', - ), + ) ?? '', '', ); } else { @@ -475,7 +476,7 @@ public function fileReferenceCreateAction( LocalizationUtility::translate( 'create_relation_error', 'examples', - ), + ) ?? '', ContextualFeedbackSeverity::ERROR, ); } @@ -492,7 +493,7 @@ public function fileReferenceCreateAction( ); } - public function getPasswordHash(string $password, string $mode): string + public function getPasswordHash(string $password, string $mode): string|null { $hashInstance = $this->passwordHashFactory->getDefaultHashInstance($mode); return $hashInstance->getHashedPassword($password); @@ -545,15 +546,15 @@ public function countAction(string $tablename = 'pages'): ResponseInterface $count = $this->tableInformationService->countRecords($tablename); $message = LocalizationUtility::translate( - key: 'record_count_message', - extensionName: 'examples', - arguments: [$count, $tablename], + 'record_count_message', + 'examples', + [$count, $tablename], ); $this->addFlashMessage( - messageBody: $message, - messageTitle: 'Information', - severity: ContextualFeedbackSeverity::INFO, + $message ?? '', + 'Information', + ContextualFeedbackSeverity::INFO, ); return $this->redirect('flash'); }