Resolve PHPStan findings

This commit is contained in:
Daniel Siepmann 2022-09-21 13:45:59 +02:00
parent 38d465f034
commit 7f76b5b1b2
7 changed files with 24 additions and 16 deletions

View file

@ -53,8 +53,8 @@ class CategoriesCounts implements DataProcessorInterface
} }
$processedData[$as] = $this->getCategoriesCount( $processedData[$as] = $this->getCategoriesCount(
$parent, (int) $parent,
$orderBy (string) $orderBy
); );
return $processedData; return $processedData;

View file

@ -42,7 +42,14 @@ class NaturalSortingProcessor implements DataProcessorInterface
array $processedData array $processedData
) { ) {
$variablePath = $cObj->stdWrapValue('variablePath', $processorConfiguration, ''); $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, ''); $variableSubPath = $cObj->stdWrapValue('variableSubPath', $processorConfiguration, '');
if (is_string($variableSubPath) === false) {
throw new \Exception('Variable Sub Path needs to be string.', 1663760908);
}
if ($variablePath === '' || $variableSubPath === '') { if ($variablePath === '' || $variableSubPath === '') {
throw new \Exception('Provide variablePath as well as variableSubPath.', 1638373263); throw new \Exception('Provide variablePath as well as variableSubPath.', 1638373263);

View file

@ -41,7 +41,7 @@ class XmlSitemapRenderer extends Typo3XmlSitemapRenderer
return parent::render($_, $typoScriptConfiguration, $request); return parent::render($_, $typoScriptConfiguration, $request);
} }
protected function initialize(array $fullConfiguration) protected function initialize(array $fullConfiguration): void
{ {
parent::initialize($fullConfiguration); parent::initialize($fullConfiguration);
$this->view->assign('settings', $this->getSettings()); $this->view->assign('settings', $this->getSettings());
@ -51,7 +51,7 @@ class XmlSitemapRenderer extends Typo3XmlSitemapRenderer
{ {
$settings = []; $settings = [];
foreach (array_keys($this->typoScriptConfiguration['userFunc.']['variables.'] ?? []) as $variableName) { foreach (array_keys($this->typoScriptConfiguration['userFunc.']['variables.'] ?? []) as $variableName) {
if (substr($variableName, -1) === '.') { if (!is_string($variableName) || substr($variableName, -1) === '.') {
continue; continue;
} }
$settings[$variableName] = $this->cObj->cObjGetSingle( $settings[$variableName] = $this->cObj->cObjGetSingle(

View file

@ -31,14 +31,15 @@ class PageLayoutHeader
/** /**
* @var array * @var array
*/ */
private $pageinfo; private $pageinfo = [];
public function render( public function render(
array $params, array $params,
PageLayoutController $pageLayoutController PageLayoutController $pageLayoutController
): string { ): string {
// @extensionScannerIgnoreLine At least in v10 this is a false positive if (is_array($pageLayoutController->pageinfo)) {
$this->pageinfo = $pageLayoutController->pageinfo; $this->pageinfo = $pageLayoutController->pageinfo;
}
// TODO: Check whether two levels up is uid 2, which holds all blog posts // TODO: Check whether two levels up is uid 2, which holds all blog posts
// To prevent rendering on non blog posts // To prevent rendering on non blog posts
@ -50,25 +51,25 @@ class PageLayoutHeader
'metaInfo' => [ 'metaInfo' => [
[ [
'label' => 'meta-description', 'label' => 'meta-description',
'value' => $this->pageinfo['description'], 'value' => $this->pageinfo['description'] ?? '',
'field' => 'description', 'field' => 'description',
'type' => 'string', 'type' => 'string',
], ],
[ [
'label' => 'introduction', 'label' => 'introduction',
'value' => $this->pageinfo['abstract'], 'value' => $this->pageinfo['abstract'] ?? '',
'field' => 'abstract', 'field' => 'abstract',
'type' => 'string', 'type' => 'string',
], ],
[ [
'label' => 'published', 'label' => 'published',
'value' => $this->pageinfo['lastUpdated'], 'value' => $this->pageinfo['lastUpdated'] ?? '',
'field' => 'lastUpdated', 'field' => 'lastUpdated',
'type' => 'date', 'type' => 'date',
], ],
[ [
'label' => 'updated', 'label' => 'updated',
'value' => $this->pageinfo['SYS_LASTCHANGED'], 'value' => $this->pageinfo['SYS_LASTCHANGED'] ?? '',
'type' => 'date', 'type' => 'date',
], ],
[ [
@ -91,7 +92,7 @@ class PageLayoutHeader
private function resolvePageMedia(): array private function resolvePageMedia(): array
{ {
$page = ['uid' => $this->pageinfo['uid']]; $page = ['uid' => $this->pageinfo['uid'] ?? ''];
$files = new FileCollector(); $files = new FileCollector();
$files->addFilesFromRelation('pages', 'media', $page); $files->addFilesFromRelation('pages', 'media', $page);

View file

@ -46,7 +46,7 @@ class CodeHighlighting
// Highlight some code. // Highlight some code.
$highlighted = $highlighter->highlightAuto($code); $highlighted = $highlighter->highlightAuto($code);
$content = '<pre><code>' . $highlighted->value . '</code></pre>'; $content = '<pre><code>' . $highlighted->value . '</code></pre>';
} catch (DomainException $e) { } catch (\DomainException $e) {
$content = '<pre><code>' . $code . '</code></pre>'; $content = '<pre><code>' . $code . '</code></pre>';
} }

View file

@ -35,7 +35,7 @@ class IdViewHelper extends AbstractViewHelper
{ {
use CompileWithContentArgumentAndRenderStatic; use CompileWithContentArgumentAndRenderStatic;
public function initializeArguments() public function initializeArguments(): void
{ {
$this->registerArgument('value', 'string', 'string to format'); $this->registerArgument('value', 'string', 'string to format');
} }
@ -51,7 +51,7 @@ class IdViewHelper extends AbstractViewHelper
} }
$value = (string)$value; $value = (string)$value;
$value = str_replace(' ', '_', $value); $value = str_replace(' ', '_', $value);
$value = preg_replace('#\W#', '', $value); $value = preg_replace('#\W#', '', $value) ?? '';
$value = GeneralUtility::underscoredToUpperCamelCase($value); $value = GeneralUtility::underscoredToUpperCamelCase($value);
$value = lcfirst($value); $value = lcfirst($value);
return $value; return $value;

View file

@ -40,7 +40,7 @@
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes( \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
$tableName, $tableName,
'rel', 'rel',
\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_LINK, (string) \TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_LINK,
'after:url' 'after:url'
); );