[BUGFIX] Fix phpstan errors from TypesAssignedToPropertiesRule
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Wed, 5 May 2021 14:17:54 +0000 (16:17 +0200)
committerBenni Mack <benni@typo3.org>
Wed, 12 May 2021 12:03:19 +0000 (14:03 +0200)
in

* EXT:workspaces
* EXT:tstemplate
* EXT:setup
* EXT:scheduler
* EXT:recycler
* EXT:lowlevel
* EXT:linkvalidator
* EXT:install
* EXT:info

Releases: master
Resolves: #94121
Change-Id: Idb153afd9763cd9c3238be68d2290bde68e88b35
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69038
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
24 files changed:
typo3/sysext/info/Classes/Controller/InfoModuleController.php
typo3/sysext/install/Classes/ExtensionScanner/Php/CodeStatistics.php
typo3/sysext/install/Classes/FolderStructure/FileNode.php
typo3/sysext/install/Classes/UpgradeAnalysis/DocumentationFile.php
typo3/sysext/linkvalidator/Classes/Report/LinkValidatorReport.php
typo3/sysext/lowlevel/Classes/Database/QueryGenerator.php
typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
typo3/sysext/recordlist/Classes/Controller/AbstractLinkBrowserController.php
typo3/sysext/recordlist/Classes/Controller/RecordListController.php
typo3/sysext/recordlist/Classes/LinkHandler/AbstractLinkHandler.php
typo3/sysext/recordlist/Classes/LinkHandler/FileLinkHandler.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
typo3/sysext/recycler/Classes/Controller/RecyclerModuleController.php
typo3/sysext/scheduler/Classes/Command/SchedulerCommand.php
typo3/sysext/scheduler/Classes/Task/AbstractTask.php
typo3/sysext/scheduler/Classes/Task/ExecuteSchedulableCommandAdditionalFieldProvider.php
typo3/sysext/setup/Classes/Controller/SetupModuleController.php
typo3/sysext/tstemplate/Classes/Controller/TemplateAnalyzerModuleFunctionController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateConstantEditorModuleFunctionController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateInformationModuleFunctionController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateModuleController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php
typo3/sysext/workspaces/Classes/Dependency/ElementEntity.php
typo3/sysext/workspaces/Classes/Domain/Model/DatabaseRecord.php

index 798e1c4..9c2c775 100644 (file)
@@ -46,7 +46,7 @@ class InfoModuleController
     /**
      * @var array Used by client classes.
      */
-    public $pageinfo;
+    public $pageinfo = [];
 
     /**
      * The name of the module
@@ -194,11 +194,11 @@ class InfoModuleController
 
         // The page will show only if there is a valid page and if this page
         // may be viewed by the user
-        $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
-        if ($this->pageinfo) {
+        $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause) ?: [];
+        if ($this->pageinfo !== []) {
             $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
         }
-        $access = is_array($this->pageinfo);
+        $access = $this->pageinfo !== [];
         if ($this->id && $access || $backendUser->isAdmin() && !$this->id) {
             if ($backendUser->isAdmin() && !$this->id) {
                 $this->pageinfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
index 030c38b..f166948 100644 (file)
@@ -29,9 +29,9 @@ use PhpParser\NodeVisitorAbstract;
 class CodeStatistics extends NodeVisitorAbstract
 {
     /**
-     * @var int True if a class statement has @extensionScannerIgnoreFile
+     * @var bool True if a class statement has @extensionScannerIgnoreFile
      */
-    protected $isCurrentFileIgnored = 0;
+    protected $isCurrentFileIgnored = false;
 
     /**
      * @var int Counts @extensionScannerIgnoreLine statements
index 2e3a97e..795c24a 100644 (file)
@@ -81,7 +81,14 @@ class FileNode extends AbstractNode implements NodeInterface
                     1380364362
                 );
             }
-            $this->targetContent = file_get_contents($structure['targetContentFile']);
+            $fileContent = file_get_contents($structure['targetContentFile']);
+            if ($fileContent === false) {
+                throw new InvalidArgumentException(
+                    'Error while reading targetContentFile ' . $structure['targetContentFile'],
+                    1380364363
+                );
+            }
+            $this->targetContent = $fileContent;
         }
     }
 
index eceb447..c2ca1e1 100644 (file)
@@ -56,10 +56,10 @@ class DocumentationFile
      */
     public function __construct(Registry $registry = null, $changelogDir = '')
     {
-        $this->registry = $registry;
-        if ($this->registry === null) {
-            $this->registry = new Registry();
+        if ($registry === null) {
+            $registry = new Registry();
         }
+        $this->registry = $registry;
         $this->changelogPath = $changelogDir !== '' ? $changelogDir : (string)realpath(ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog');
         $this->changelogPath = str_replace('\\', '/', $this->changelogPath);
     }
index 20af3f9..f74dccb 100644 (file)
@@ -352,8 +352,8 @@ class LinkValidatorReport
             $this->hookObjectsArr[$linkType] = $hookObject;
         }
 
-        $this->pageRecord = BackendUtility::readPageAccess($this->id, $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW));
-        if (($this->id && is_array($this->pageRecord)) || (!$this->id && $this->getBackendUser()->isAdmin())) {
+        $this->pageRecord = BackendUtility::readPageAccess($this->id, $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)) ?: [];
+        if (($this->id && $this->pageRecord !== []) || (!$this->id && $this->getBackendUser()->isAdmin())) {
             $this->isAccessibleForCurrentUser = true;
         }
         // Don't access in workspace
index 770ffa4..a9d198e 100644 (file)
@@ -354,7 +354,7 @@ class QueryGenerator
         if ($this->table && is_array($GLOBALS['TCA'][$this->table])) {
             if ($mQ) {
                 // Show query
-                $this->enablePrefix = 1;
+                $this->enablePrefix = true;
                 $queryString = $this->getQuery($this->queryConfig);
                 $selectQueryString = $this->getSelectQuery($queryString);
                 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->table);
@@ -608,7 +608,7 @@ class QueryGenerator
             if ($saveArr['queryTable']) {
                 $this->init('queryConfig', $saveArr['queryTable'], '', $this->settings);
                 $this->makeSelectorTable($saveArr);
-                $this->enablePrefix = 1;
+                $this->enablePrefix = true;
                 $queryString = $this->getQuery($this->queryConfig);
 
                 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
@@ -1576,9 +1576,9 @@ class QueryGenerator
     /**
      * Process data
      *
-     * @param string $qC Query config
+     * @param array $qC Query config
      */
-    protected function procesData($qC = '')
+    protected function procesData($qC = [])
     {
         $this->queryConfig = $qC;
         $POST = GeneralUtility::_POST();
@@ -2570,7 +2570,7 @@ class QueryGenerator
                 $this->extFieldLists['queryOrder_SQL'] = implode(',', $reList);
             }
             // Query Generator:
-            $this->procesData($modSettings['queryConfig'] ? unserialize($modSettings['queryConfig'], ['allowed_classes' => false]) : '');
+            $this->procesData($modSettings['queryConfig'] ? unserialize($modSettings['queryConfig'], ['allowed_classes' => false]) : []);
             $this->queryConfig = $this->cleanUpQueryConfig($this->queryConfig);
             $this->enableQueryParts = (bool)$modSettings['search_query_smallparts'];
             $codeArr = $this->getFormElements();
index e771b58..6f54d08 100644 (file)
@@ -22,6 +22,7 @@ use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\FileInterface;
 use TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter;
 use TYPO3\CMS\Core\Resource\Folder;
+use TYPO3\CMS\Core\Resource\FolderInterface;
 use TYPO3\CMS\Core\Resource\ProcessedFile;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\Search\FileSearchDemand;
@@ -50,7 +51,7 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
     protected $expandFolder;
 
     /**
-     * @var Folder
+     * @var FolderInterface
      */
     protected $selectedFolder;
 
@@ -157,7 +158,9 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
         if (!$this->selectedFolder) {
             try {
                 [, $pid, $table,, $field] = explode('-', explode('|', $this->bparams)[4]);
-                $this->selectedFolder = $backendUser->getDefaultUploadFolder($pid, $table, $field);
+                if (($defaultUploadFolder = $backendUser->getDefaultUploadFolder($pid, $table, $field)) instanceof FolderInterface) {
+                    $this->selectedFolder = $defaultUploadFolder;
+                }
             } catch (\Exception $e) {
                 // The configured default user folder does not exist
             }
@@ -209,12 +212,12 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
     /**
      * For TYPO3 Element Browser: Expand folder of files.
      *
-     * @param Folder $folder The folder path to expand
+     * @param FolderInterface $folder The folder path to expand
      * @param array $extensionList List of fileextensions to show
      * @param bool $noThumbs Whether to show thumbnails or not. If set, no thumbnails are shown.
      * @return string HTML output
      */
-    public function renderFilesInFolder(Folder $folder, array $extensionList = [], $noThumbs = false)
+    public function renderFilesInFolder(FolderInterface $folder, array $extensionList = [], $noThumbs = false)
     {
         if (!$folder->checkActionPermission('read')) {
             return '';
@@ -330,11 +333,11 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
     /**
      * Get a list of Files in a folder filtered by extension
      *
-     * @param Folder $folder
+     * @param FolderInterface $folder
      * @param array $extensionList
      * @return File[]
      */
-    protected function getFilesInFolder(Folder $folder, array $extensionList)
+    protected function getFilesInFolder(FolderInterface $folder, array $extensionList)
     {
         if (!empty($extensionList)) {
             /** @var FileExtensionFilter $filter */
index 82a62fb..ce7f043 100644 (file)
@@ -72,7 +72,7 @@ abstract class AbstractLinkBrowserController
     /**
      * Link handler responsible for the current active link
      *
-     * @var LinkHandlerInterface $currentLinkHandler
+     * @var LinkHandlerInterface|null
      */
     protected $currentLinkHandler;
 
@@ -400,10 +400,8 @@ abstract class AbstractLinkBrowserController
             // empty the current link
             $this->currentLinkParts = [];
             $this->currentLinkHandler = null;
-            $this->currentLinkHandler = '';
             // select first tab
-            reset($menuDef);
-            $this->displayedLinkHandlerId = key($menuDef);
+            $this->displayedLinkHandlerId = (string)array_key_first($menuDef);
             $this->displayedLinkHandler = $this->linkHandlers[$this->displayedLinkHandlerId]['handlerInstance'];
             $menuDef[$this->displayedLinkHandlerId]['isActive'] = true;
         }
index 307aa31..90cbe75 100644 (file)
@@ -180,7 +180,7 @@ class RecordListController
         $dblist->tableTSconfigOverTCA = $this->modTSconfig['table.'];
         $dblist->allowedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['allowedNewTables'], true);
         $dblist->deniedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['deniedNewTables'], true);
-        $dblist->pageRow = $pageinfo;
+        $dblist->pageRow = $this->pageInfo;
         $dblist->modTSconfig = $this->modTSconfig;
         $dblist->setLanguagesAllowedForUser($this->siteLanguages);
         $clickTitleMode = trim($this->modTSconfig['clickTitleMode']);
index 5f16be6..4c53e74 100644 (file)
@@ -55,7 +55,7 @@ abstract class AbstractLinkHandler
     protected $iconFactory;
 
     /**
-     * @var \TYPO3\CMS\Fluid\View\StandaloneView
+     * @var ViewInterface
      */
     protected $view;
 
index 6b5d815..5037fbf 100644 (file)
@@ -106,12 +106,12 @@ class FileLinkHandler extends AbstractLinkHandler implements LinkHandlerInterfac
 
         $this->expandFolder = $request->getQueryParams()['expandFolder'] ?? null;
         if (!empty($this->linkParts) && !isset($this->expandFolder)) {
-            $this->expandFolder = $this->linkParts['url'][$this->mode];
-            if ($this->expandFolder instanceof File) {
-                $this->expandFolder = $this->expandFolder->getParentFolder();
+            $fileOrFolder = $this->linkParts['url'][$this->mode];
+            if ($fileOrFolder instanceof File) {
+                $fileOrFolder = $fileOrFolder->getParentFolder();
             }
-            if ($this->expandFolder instanceof Folder) {
-                $this->expandFolder = $this->expandFolder->getCombinedIdentifier();
+            if ($fileOrFolder instanceof Folder) {
+                $this->expandFolder = $fileOrFolder->getCombinedIdentifier();
             }
         }
 
index 3b03f84..2eca17b 100644 (file)
@@ -878,10 +878,9 @@ class DatabaseRecordList
         $titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'];
         $languageService = $this->getLanguageService();
         $rowOutput = '';
-        $id_orig = null;
+        $id_orig = $this->id;
         // If in search mode, make sure the preview will show the correct page
         if ((string)$this->searchString !== '') {
-            $id_orig = $this->id;
             $this->id = $row['pid'];
         }
 
index 8701d60..2dcc7ca 100644 (file)
@@ -99,8 +99,8 @@ class RecyclerModuleController
     {
         $this->id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
         $backendUser = $this->getBackendUser();
-        $this->pageRecord = BackendUtility::readPageAccess($this->id, $backendUser->getPagePermsClause(Permission::PAGE_SHOW));
-        $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->getBackendUser()->isAdmin();
+        $this->pageRecord = BackendUtility::readPageAccess($this->id, $backendUser->getPagePermsClause(Permission::PAGE_SHOW)) ?: [];
+        $this->isAccessibleForCurrentUser = ($this->id && $this->pageRecord !== []) || (!$this->id && $this->getBackendUser()->isAdmin());
         $this->moduleTemplate = $this->moduleTemplateFactory->create($request);
 
         // don't access in workspace
index d6fbe62..ddaf8cc 100644 (file)
@@ -21,6 +21,7 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
 use TYPO3\CMS\Core\Core\Bootstrap;
+use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Scheduler\Scheduler;
 use TYPO3\CMS\Scheduler\Task\AbstractTask;
 
@@ -47,7 +48,7 @@ class SchedulerCommand extends Command
     /**
      * Array of tasks UIDs that should be executed. Null if task option is not provided.
      *
-     * @var int[]|array|null
+     * @var int[]|null
      */
     protected $overwrittenTaskList;
 
@@ -112,6 +113,9 @@ Call it like this: typo3/sysext/core/bin/typo3 scheduler:run --task=13 -f')
         Bootstrap::initializeBackendAuthentication();
 
         $overwrittenTaskList = $input->getOption('task');
+        $overwrittenTaskList = is_array($overwrittenTaskList) ? $overwrittenTaskList : [];
+        $overwrittenTaskList = array_filter($overwrittenTaskList, fn ($value) => MathUtility::canBeInterpretedAsInteger($value));
+        $overwrittenTaskList = array_map('intval', $overwrittenTaskList);
         if ($overwrittenTaskList !== []) {
             $this->overwrittenTaskList = $overwrittenTaskList;
         }
index baad127..6eee0d6 100644 (file)
@@ -41,7 +41,7 @@ abstract class AbstractTask implements LoggerAwareInterface
     /**
      * Reference to a scheduler object
      *
-     * @var \TYPO3\CMS\Scheduler\Scheduler
+     * @var \TYPO3\CMS\Scheduler\Scheduler|null
      */
     protected $scheduler;
 
@@ -301,7 +301,7 @@ abstract class AbstractTask implements LoggerAwareInterface
     public function unsetScheduler()
     {
         $this->scheduler = null;
-        $this->logger = null;
+        unset($this->logger);
     }
 
     /**
index bdc08a6..429aef5 100644 (file)
@@ -42,7 +42,7 @@ class ExecuteSchedulableCommandAdditionalFieldProvider implements AdditionalFiel
     protected $schedulableCommands = [];
 
     /**
-     * @var ExecuteSchedulableCommandTask
+     * @var ExecuteSchedulableCommandTask|null
      */
     protected $task;
 
index 453fc48..011d8c5 100644 (file)
@@ -129,7 +129,7 @@ class SetupModuleController
     /**
      * Form protection instance
      *
-     * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection
+     * @var \TYPO3\CMS\Core\FormProtection\AbstractFormProtection
      */
     protected $formProtection;
 
index db7bff8..c740dfa 100644 (file)
@@ -37,7 +37,7 @@ class TemplateAnalyzerModuleFunctionController
 
     /**
      * The currently selected sys_template record
-     * @var array
+     * @var array|null
      */
     protected $templateRow;
 
index 3ee5bdb..219dbea 100644 (file)
@@ -39,7 +39,7 @@ class TypoScriptTemplateConstantEditorModuleFunctionController
 
     /**
      * The currently selected sys_template record
-     * @var array
+     * @var array|null
      */
     protected $templateRow;
 
@@ -136,7 +136,7 @@ class TypoScriptTemplateConstantEditorModuleFunctionController
             $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
             // Update template ?
             if ($this->request->getParsedBody()['_savedok'] ?? false) {
-                $this->templateService->changed = 0;
+                $this->templateService->changed = false;
                 $this->templateService->ext_procesInput($this->request->getParsedBody(), [], $this->constants, $this->templateRow);
                 if ($this->templateService->changed) {
                     // Set the data to be saved
index b9d51a4..40f7a6a 100644 (file)
@@ -38,7 +38,7 @@ class TypoScriptTemplateInformationModuleFunctionController
 
     /**
      * The currently selected sys_template record
-     * @var array
+     * @var array|null
      */
     protected $templateRow;
 
index 013c1ab..872c27b 100644 (file)
@@ -217,7 +217,7 @@ class TypoScriptTemplateModuleController
 
         // Access check...
         // The page will show only if there is a valid page and if this page may be viewed by the user
-        $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
+        $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause) ?: [];
         $this->access = is_array($this->pageinfo);
         $view = $this->getFluidTemplateObject('tstemplate');
         if ($this->id && $this->access) {
index 5cde11d..bd782a7 100644 (file)
@@ -43,7 +43,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController
 
     /**
      * The currently selected sys_template record
-     * @var array
+     * @var array|null
      */
     protected $templateRow;
 
index 5b043b4..ad889f5 100644 (file)
@@ -76,7 +76,7 @@ class ElementEntity
     protected $traversingParents = false;
 
     /**
-     * @var ElementEntity
+     * @var ElementEntity|false
      */
     protected $outerMostParent;
 
index 0bed580..a324d57 100644 (file)
@@ -34,7 +34,7 @@ class DatabaseRecord
     protected $uid;
 
     /**
-     * @var array
+     * @var array|null
      */
     protected $row;