Skip to content

Commit

Permalink
Cleanup add phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbochmann committed Mar 13, 2024
1 parent 797e50f commit f2ca9c2
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/workflows/phpci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
command:
- "test:phpcs"
- "test:phpcompatibility"
- "test:phpstan"
php-version:
- "7.4"
- "8.0"
Expand Down
3 changes: 0 additions & 3 deletions Classes/Action/Ajax/ContentRendererAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
3 changes: 1 addition & 2 deletions Classes/Action/FlashMessageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/Action/MarkdownAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']])
);
Expand Down
6 changes: 3 additions & 3 deletions Classes/Action/ShowTemplateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ShowTemplateAction extends AbstractAction
/**
* @param RequestInterface $request
*
* @return null
* @return null|string
*/
protected function handleRequest(RequestInterface $request)
{
Expand All @@ -57,7 +57,7 @@ protected function handleRequest(RequestInterface $request)
/**
* Returns the data to render for the view.
*
* @return array
* @return BaseModel
*/
protected function getItem()
{
Expand All @@ -72,7 +72,7 @@ protected function getItem()
/**
* Returns the data to render for the view.
*
* @return array
* @return array|null
*/
protected function getData()
{
Expand Down
4 changes: 3 additions & 1 deletion Classes/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public function handleFatalError()

return true;
}

return false;
}

/**
Expand All @@ -164,7 +166,7 @@ protected function getLastError()
*
* @param string $exceptionMessage
*
* @return \Sys25\RnBase\Typo3Wrapper\Core\Error\Exception
* @return \Exception
*/
protected function getTypo3Exception($exceptionMessage)
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/ErrorHandler/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions Classes/Routing/Aspect/StaticNumberRangeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion Classes/Session/FlashMessageStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion Classes/Updates/MigrateOldMktoolsPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/CacheUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function isApcUsed()
}

/**
* @return bool
* @return string
*/
public static function getApcCacheBackendClass()
{
Expand Down
4 changes: 2 additions & 2 deletions Classes/Utility/Menu/Processor/TranslatedRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 2 additions & 12 deletions Classes/Utility/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function isAjaxContentRendererActive()
}

/**
* @return string
* @return string|int
*/
public static function getExceptionPage()
{
Expand All @@ -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.']
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/SessionUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/T3Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
final class T3Loader
{
/**
* @var array[TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer]
* @var array[\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer]
*/
private static $cObj = [];

Expand Down
2 changes: 0 additions & 2 deletions Tests/Classes/ContentObject/UserContentObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions Tests/Classes/ContentObject/UserInternalContentObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -109,13 +112,18 @@
"[ -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"
],
"test": [
"@test:phpcs",
"@test:phpcompatibility",
"@test:phpstan",
"@test:phpunit"
],
"fix:phpcs": [
Expand Down
34 changes: 34 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f2ca9c2

Please sign in to comment.