diff --git a/.github/workflows/phpci.yml b/.github/workflows/phpci.yml index 0bf5e04..ce01315 100644 --- a/.github/workflows/phpci.yml +++ b/.github/workflows/phpci.yml @@ -67,6 +67,7 @@ jobs: command: - "test:phpcs" - "test:phpcompatibility" + - "test:phpstan" php-version: - "7.4" - "8.0" diff --git a/Classes/Action/Ajax/ContentRendererAction.php b/Classes/Action/Ajax/ContentRendererAction.php index 6993a03..7be9955 100644 --- a/Classes/Action/Ajax/ContentRendererAction.php +++ b/Classes/Action/Ajax/ContentRendererAction.php @@ -39,9 +39,6 @@ class ContentRendererAction { /** * Entry point. - * - * @param array current data record, either a tt_content element or page record - * @param string table name, either "pages" or "tt_content" */ public function renderContent() { diff --git a/Classes/Action/FlashMessageAction.php b/Classes/Action/FlashMessageAction.php index aa21e70..f550636 100644 --- a/Classes/Action/FlashMessageAction.php +++ b/Classes/Action/FlashMessageAction.php @@ -40,10 +40,9 @@ class FlashMessageAction extends AbstractAction /** * @param RequestInterface $request * - * @return null + * @return null|string * * @throws \Sys25\RnBase\Exception\SkipActionException - * @throws \tx_rnbase_exception_Skip */ protected function handleRequest(RequestInterface $request) { diff --git a/Classes/Action/MarkdownAction.php b/Classes/Action/MarkdownAction.php index 3b2edbf..5bfd3b7 100644 --- a/Classes/Action/MarkdownAction.php +++ b/Classes/Action/MarkdownAction.php @@ -93,7 +93,7 @@ protected function auth() TYPO3::getBEUserUID() // check crypt auth users from ts || ( - $_SERVER['PHP_AUTH_USER'] ?? false + ($_SERVER['PHP_AUTH_USER'] ?? false) && isset($auth[$_SERVER['PHP_AUTH_USER']]) && $auth[$_SERVER['PHP_AUTH_USER']] === crypt($_SERVER['PHP_AUTH_PW'], $auth[$_SERVER['PHP_AUTH_USER']]) ); diff --git a/Classes/Action/ShowTemplateAction.php b/Classes/Action/ShowTemplateAction.php index e58e725..60c17af 100644 --- a/Classes/Action/ShowTemplateAction.php +++ b/Classes/Action/ShowTemplateAction.php @@ -43,7 +43,7 @@ class ShowTemplateAction extends AbstractAction /** * @param RequestInterface $request * - * @return null + * @return null|string */ protected function handleRequest(RequestInterface $request) { @@ -57,7 +57,7 @@ protected function handleRequest(RequestInterface $request) /** * Returns the data to render for the view. * - * @return array + * @return BaseModel */ protected function getItem() { @@ -72,7 +72,7 @@ protected function getItem() /** * Returns the data to render for the view. * - * @return array + * @return array|null */ protected function getData() { diff --git a/Classes/ErrorHandler/ErrorHandler.php b/Classes/ErrorHandler/ErrorHandler.php index d7d36fc..377ed8d 100644 --- a/Classes/ErrorHandler/ErrorHandler.php +++ b/Classes/ErrorHandler/ErrorHandler.php @@ -147,6 +147,8 @@ public function handleFatalError() return true; } + + return false; } /** @@ -164,7 +166,7 @@ protected function getLastError() * * @param string $exceptionMessage * - * @return \Sys25\RnBase\Typo3Wrapper\Core\Error\Exception + * @return \Exception */ protected function getTypo3Exception($exceptionMessage) { diff --git a/Classes/ErrorHandler/ExceptionHandler.php b/Classes/ErrorHandler/ExceptionHandler.php index dbb4075..d1e1c11 100644 --- a/Classes/ErrorHandler/ExceptionHandler.php +++ b/Classes/ErrorHandler/ExceptionHandler.php @@ -284,7 +284,7 @@ protected function echoExceptionPageAndExit($absoluteExceptionPageUrl) /** * Methode ist in TYPO3 4.5.x noch nicht vorhanden. Daher selbst eingefügt. * - * @param \Exception $exception + * @param \Throwable|\Exception $exception */ protected function sendStatusHeadersEnvironment($exception) { diff --git a/Classes/Routing/Aspect/StaticNumberRangeMapper.php b/Classes/Routing/Aspect/StaticNumberRangeMapper.php index ad9a04d..c32b4ff 100644 --- a/Classes/Routing/Aspect/StaticNumberRangeMapper.php +++ b/Classes/Routing/Aspect/StaticNumberRangeMapper.php @@ -66,12 +66,12 @@ class StaticNumberRangeMapper implements StaticMappableAspectInterface public const MAX_PAGE_LIMIT = 1000; /** - * @var string + * @var int */ protected $start; /** - * @var string + * @var int */ protected $end; diff --git a/Classes/Session/FlashMessageStorage.php b/Classes/Session/FlashMessageStorage.php index 95d7017..a183054 100644 --- a/Classes/Session/FlashMessageStorage.php +++ b/Classes/Session/FlashMessageStorage.php @@ -193,7 +193,7 @@ public function getMessages() * @param string $method * @param array $args * - * @return self + * @return self|null * * @throws RuntimeException If level or method does not exists */ @@ -209,5 +209,7 @@ public static function __callStatic($method, $args) if (defined('self::'.$const)) { return self::getInstance()->addMessage($args[0], constant('self::'.$const)); } + + return null; } } diff --git a/Classes/Updates/MigrateOldMktoolsPlugins.php b/Classes/Updates/MigrateOldMktoolsPlugins.php index 6e6f5aa..4ce5eb6 100644 --- a/Classes/Updates/MigrateOldMktoolsPlugins.php +++ b/Classes/Updates/MigrateOldMktoolsPlugins.php @@ -132,7 +132,7 @@ protected function getPreparedQueryBuilder(): QueryBuilder { $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable(self::TABLE_NAME); $queryBuilder->getRestrictions()->removeAll(); - $whereConditions = []; + $whereConditionsForOldClasses = []; foreach ($this->classMappings as $oldClass => $newClass) { $whereConditionsForOldClasses[] = $queryBuilder->expr()->like( 'pi_flexform', diff --git a/Classes/Utility/CacheUtility.php b/Classes/Utility/CacheUtility.php index 368f089..b5ff710 100644 --- a/Classes/Utility/CacheUtility.php +++ b/Classes/Utility/CacheUtility.php @@ -73,7 +73,7 @@ public static function isApcUsed() } /** - * @return bool + * @return string */ public static function getApcCacheBackendClass() { diff --git a/Classes/Utility/Menu/Processor/TranslatedRecords.php b/Classes/Utility/Menu/Processor/TranslatedRecords.php index 5ed8302..bbf625d 100644 --- a/Classes/Utility/Menu/Processor/TranslatedRecords.php +++ b/Classes/Utility/Menu/Processor/TranslatedRecords.php @@ -122,7 +122,7 @@ public function process(array $menuItems, array $typoScriptConfiguration): array * * @param string $value * - * @return bool + * @return bool|string */ public function processEmptyIfRecordNotExists($value, array $typoScriptConfiguration) { @@ -195,7 +195,7 @@ protected function handleDisablingOfMenuItemForNotTranslatedRecord( $typoScriptFrontendController = $this->getTypoScriptFrontendController(); $pageTranslationVisibility = new PageTranslationVisibility( - (int) $typoScriptFrontendController->page['l18n_cfg'] ?? 0 + (int) ($typoScriptFrontendController->page['l18n_cfg'] ?? 0) ); if ($pageTranslationVisibility->shouldHideTranslationIfNoTranslatedRecordExists() diff --git a/Classes/Utility/Misc.php b/Classes/Utility/Misc.php index 337f518..c8a2ba1 100644 --- a/Classes/Utility/Misc.php +++ b/Classes/Utility/Misc.php @@ -79,7 +79,7 @@ public static function isAjaxContentRendererActive() } /** - * @return string + * @return string|int */ public static function getExceptionPage() { @@ -103,7 +103,7 @@ public static function getConfigurations($staticPath, $additionalPath = '') ); } - $pageTSconfig = BackendUtility::getPagesTSconfig(0, 1); + $pageTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig(0); $config = Arrays::mergeRecursiveWithOverrule( (array) $pageTSconfig['config.']['tx_mktools.'], (array) $pageTSconfig['plugin.']['tx_mktools.'] @@ -118,16 +118,6 @@ public static function getConfigurations($staticPath, $additionalPath = '') return $configurations; } - /** - * @param string $filename - * - * @return string - */ - private static function getAbsoluteFileName($filename) - { - return Files::getFileAbsFileName($filename); - } - public static function areUnmappedPageTypesAllowed(): bool { return (bool) self::getExtensionCfgValue('allowUnmappedPageTypes'); diff --git a/Classes/Utility/SessionUtility.php b/Classes/Utility/SessionUtility.php index 5962c14..ec0e29e 100644 --- a/Classes/Utility/SessionUtility.php +++ b/Classes/Utility/SessionUtility.php @@ -119,7 +119,7 @@ public static function areCookiesActivated() } else { // @TODO diesen Abschnitt testen, aber wie (vor allem auf CLI)? // Wir versuchen selbst einen Cookie zu setzen. - setcookie('cookiesActivated', 1, time() + 3600); + setcookie('cookiesActivated', '1', time() + 3600); // Wir setzen einen Parameter für den Reload, // um einen Infinite Redirect zu verhindern // falls keine Cookies erlaubt sind. diff --git a/Classes/Utility/T3Loader.php b/Classes/Utility/T3Loader.php index 944c226..6f4154f 100644 --- a/Classes/Utility/T3Loader.php +++ b/Classes/Utility/T3Loader.php @@ -37,7 +37,7 @@ final class T3Loader { /** - * @var array[TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer] + * @var array[\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer] */ private static $cObj = []; diff --git a/Tests/Classes/ContentObject/UserContentObjectTest.php b/Tests/Classes/ContentObject/UserContentObjectTest.php index 987572d..58aa0c7 100644 --- a/Tests/Classes/ContentObject/UserContentObjectTest.php +++ b/Tests/Classes/ContentObject/UserContentObjectTest.php @@ -88,8 +88,6 @@ public function testRenderIfContentShouldNotBeLoadedWithAjax($loadWithAjax, $mkt /** * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject - * - * @return \PHPUnit_Framework_MockObject_MockObject|\DMK\Mktools\ContentObject\UserContentObject */ protected function initializeFixtures($contentObject) { diff --git a/Tests/Classes/ContentObject/UserInternalContentObjectTest.php b/Tests/Classes/ContentObject/UserInternalContentObjectTest.php index b07edb2..1a9be98 100644 --- a/Tests/Classes/ContentObject/UserInternalContentObjectTest.php +++ b/Tests/Classes/ContentObject/UserInternalContentObjectTest.php @@ -80,8 +80,6 @@ public function testRenderIfContentShouldNotBeLoadedWithAjax($loadWithAjax, $mkt /** * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject - * - * @return \PHPUnit_Framework_MockObject_MockObject|\DMK\Mktools\ContentObject\UserInternalContentObject */ protected function initializeFixtures($contentObject) { diff --git a/composer.json b/composer.json index cc7d6f4..dd02523 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,10 @@ "typo3/testing-framework": "^6.0 || ^7.0", "phpunit/phpunit": "^9.0", "phpcompatibility/php-compatibility": "^9.3.5", - "phpspec/prophecy-phpunit": "^2.0" + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/phpstan": "^1.1", + "saschaegerer/phpstan-typo3": "^1.9", + "phpstan/extension-installer": "*" }, "autoload": { "psr-4": { @@ -109,6 +112,10 @@ "[ -e .Build/bin/phpcs ] || composer update", ".Build/bin/phpcs --ignore=.Build/*,Resources/Public/* -p . --standard=.Build/vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2" ], + "test:phpstan": [ + "[ -e .Build/bin/phpstan ] || composer update --ansi", + ".Build/bin/phpstan analyse -c phpstan.neon --memory-limit=512M --ansi" + ], "test:phpunit": [ "[ -e .Build/bin/phpunit ] || composer update --ansi", "export TYPO3_PATH_APP=$PWD/.Build && export TYPO3_PATH_WEB=$PWD/.Build/Web && .Build/bin/phpunit -c phpunit.xml.dist --colors=always" @@ -116,6 +123,7 @@ "test": [ "@test:phpcs", "@test:phpcompatibility", + "@test:phpstan", "@test:phpunit" ], "fix:phpcs": [ diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..c2fd74b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,34 @@ +parameters: + level: 5 + bootstrapFiles: + - "%currentWorkingDirectory%/.Build/vendor/autoload.php" + - "%currentWorkingDirectory%/Resources/Private/PHP/Composer/autoload.php" + paths: + - %currentWorkingDirectory%/Classes + - %currentWorkingDirectory%/ext_localconf.php + - %currentWorkingDirectory%/ext_emconf.php + reportUnmatchedIgnoredErrors: false + ignoreErrors: + - + message: "#^Constant LF not found\\.$#" + count: 1 + path: Classes/Command/MigrateSwitchableControllerActionsCommand.php + + - + message: "#^Call to static method addRulesForFrontend\\(\\) on an unknown class DMK\\\\MkSanitizedParameters\\\\Rules\\.$#" + count: 1 + path: ext_localconf.php + - + message: "#^Call to method checkRecord\\(\\) on an unknown class TYPO3\\\\CMS\\\\Frontend\\\\Page\\\\PageRepository\\.$#" + count: 1 + path: Classes/Action/Ajax/ContentRendererAction.php + + - + message: "#^Call to method getLanguageOverlay\\(\\) on an unknown class TYPO3\\\\CMS\\\\Frontend\\\\Page\\\\PageRepository\\.$#" + count: 1 + path: Classes/Utility/Menu/Processor/TranslatedRecords.php + + - + message: "#^Call to method getRecordOverlay\\(\\) on an unknown class TYPO3\\\\CMS\\\\Frontend\\\\Page\\\\PageRepository\\.$#" + count: 1 + path: Classes/Utility/Menu/Processor/TranslatedRecords.php