From 7f76b5b1b2576e8f5879777c8aaea9aa6ddee580 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 21 Sep 2022 13:45:59 +0200 Subject: [PATCH] Resolve PHPStan findings --- .../DataProcessing/CategoriesCounts.php | 4 ++-- .../DataProcessing/NaturalSortingProcessor.php | 7 +++++++ Classes/Frontend/RssFeed/XmlSitemapRenderer.php | 4 ++-- Classes/Hooks/Backend/PageLayoutHeader.php | 17 +++++++++-------- Classes/UserFunction/CodeHighlighting.php | 2 +- Classes/ViewHelpers/Format/IdViewHelper.php | 4 ++-- Configuration/TCA/Overrides/pages.php | 2 +- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Classes/Frontend/DataProcessing/CategoriesCounts.php b/Classes/Frontend/DataProcessing/CategoriesCounts.php index 0bffcce..dc1c4cb 100644 --- a/Classes/Frontend/DataProcessing/CategoriesCounts.php +++ b/Classes/Frontend/DataProcessing/CategoriesCounts.php @@ -53,8 +53,8 @@ class CategoriesCounts implements DataProcessorInterface } $processedData[$as] = $this->getCategoriesCount( - $parent, - $orderBy + (int) $parent, + (string) $orderBy ); return $processedData; diff --git a/Classes/Frontend/DataProcessing/NaturalSortingProcessor.php b/Classes/Frontend/DataProcessing/NaturalSortingProcessor.php index b7eed5e..54bc41d 100644 --- a/Classes/Frontend/DataProcessing/NaturalSortingProcessor.php +++ b/Classes/Frontend/DataProcessing/NaturalSortingProcessor.php @@ -42,7 +42,14 @@ class NaturalSortingProcessor implements DataProcessorInterface array $processedData ) { $variablePath = $cObj->stdWrapValue('variablePath', $processorConfiguration, ''); + if (is_string($variablePath) === false) { + throw new \Exception('Variable path needs to be string.', 1663760889); + } + $variableSubPath = $cObj->stdWrapValue('variableSubPath', $processorConfiguration, ''); + if (is_string($variableSubPath) === false) { + throw new \Exception('Variable Sub Path needs to be string.', 1663760908); + } if ($variablePath === '' || $variableSubPath === '') { throw new \Exception('Provide variablePath as well as variableSubPath.', 1638373263); diff --git a/Classes/Frontend/RssFeed/XmlSitemapRenderer.php b/Classes/Frontend/RssFeed/XmlSitemapRenderer.php index dd65e46..9c96d09 100644 --- a/Classes/Frontend/RssFeed/XmlSitemapRenderer.php +++ b/Classes/Frontend/RssFeed/XmlSitemapRenderer.php @@ -41,7 +41,7 @@ class XmlSitemapRenderer extends Typo3XmlSitemapRenderer return parent::render($_, $typoScriptConfiguration, $request); } - protected function initialize(array $fullConfiguration) + protected function initialize(array $fullConfiguration): void { parent::initialize($fullConfiguration); $this->view->assign('settings', $this->getSettings()); @@ -51,7 +51,7 @@ class XmlSitemapRenderer extends Typo3XmlSitemapRenderer { $settings = []; foreach (array_keys($this->typoScriptConfiguration['userFunc.']['variables.'] ?? []) as $variableName) { - if (substr($variableName, -1) === '.') { + if (!is_string($variableName) || substr($variableName, -1) === '.') { continue; } $settings[$variableName] = $this->cObj->cObjGetSingle( diff --git a/Classes/Hooks/Backend/PageLayoutHeader.php b/Classes/Hooks/Backend/PageLayoutHeader.php index 33cbae2..c5cc2ae 100644 --- a/Classes/Hooks/Backend/PageLayoutHeader.php +++ b/Classes/Hooks/Backend/PageLayoutHeader.php @@ -31,14 +31,15 @@ class PageLayoutHeader /** * @var array */ - private $pageinfo; + private $pageinfo = []; public function render( array $params, PageLayoutController $pageLayoutController ): string { - // @extensionScannerIgnoreLine At least in v10 this is a false positive - $this->pageinfo = $pageLayoutController->pageinfo; + if (is_array($pageLayoutController->pageinfo)) { + $this->pageinfo = $pageLayoutController->pageinfo; + } // TODO: Check whether two levels up is uid 2, which holds all blog posts // To prevent rendering on non blog posts @@ -50,25 +51,25 @@ class PageLayoutHeader 'metaInfo' => [ [ 'label' => 'meta-description', - 'value' => $this->pageinfo['description'], + 'value' => $this->pageinfo['description'] ?? '', 'field' => 'description', 'type' => 'string', ], [ 'label' => 'introduction', - 'value' => $this->pageinfo['abstract'], + 'value' => $this->pageinfo['abstract'] ?? '', 'field' => 'abstract', 'type' => 'string', ], [ 'label' => 'published', - 'value' => $this->pageinfo['lastUpdated'], + 'value' => $this->pageinfo['lastUpdated'] ?? '', 'field' => 'lastUpdated', 'type' => 'date', ], [ 'label' => 'updated', - 'value' => $this->pageinfo['SYS_LASTCHANGED'], + 'value' => $this->pageinfo['SYS_LASTCHANGED'] ?? '', 'type' => 'date', ], [ @@ -91,7 +92,7 @@ class PageLayoutHeader private function resolvePageMedia(): array { - $page = ['uid' => $this->pageinfo['uid']]; + $page = ['uid' => $this->pageinfo['uid'] ?? '']; $files = new FileCollector(); $files->addFilesFromRelation('pages', 'media', $page); diff --git a/Classes/UserFunction/CodeHighlighting.php b/Classes/UserFunction/CodeHighlighting.php index 545cc37..ba38eea 100644 --- a/Classes/UserFunction/CodeHighlighting.php +++ b/Classes/UserFunction/CodeHighlighting.php @@ -46,7 +46,7 @@ class CodeHighlighting // Highlight some code. $highlighted = $highlighter->highlightAuto($code); $content = '
' . $highlighted->value . '
'; - } catch (DomainException $e) { + } catch (\DomainException $e) { $content = '
' . $code . '
'; } diff --git a/Classes/ViewHelpers/Format/IdViewHelper.php b/Classes/ViewHelpers/Format/IdViewHelper.php index ee7deb6..0deeeab 100644 --- a/Classes/ViewHelpers/Format/IdViewHelper.php +++ b/Classes/ViewHelpers/Format/IdViewHelper.php @@ -35,7 +35,7 @@ class IdViewHelper extends AbstractViewHelper { use CompileWithContentArgumentAndRenderStatic; - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'string', 'string to format'); } @@ -51,7 +51,7 @@ class IdViewHelper extends AbstractViewHelper } $value = (string)$value; $value = str_replace(' ', '_', $value); - $value = preg_replace('#\W#', '', $value); + $value = preg_replace('#\W#', '', $value) ?? ''; $value = GeneralUtility::underscoredToUpperCamelCase($value); $value = lcfirst($value); return $value; diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php index 057b120..8190331 100644 --- a/Configuration/TCA/Overrides/pages.php +++ b/Configuration/TCA/Overrides/pages.php @@ -40,7 +40,7 @@ \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes( $tableName, 'rel', - \TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_LINK, + (string) \TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_LINK, 'after:url' );