Commit 1bf66b3d authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Daniel Goerz
Browse files

[TASK] Activate AppendedArrayItemTypeRule phpstan rule

Releases: master
Resolves: #94073
Change-Id: I2a17bfd5d9cf4fce0915e466dd48e266dc6485b7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69035


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 06455d8e
......@@ -72,7 +72,9 @@ class NodeVisitor extends NodeVisitorAbstract
// annotations shipped with doctrine/annotations
'Doctrine\\\\Common\\\\Annotations\\\\Annotation\\\\Enum', 'Enum',
// Extension scanner
'extensionScannerIgnoreFile', 'extensionScannerIgnoreLine'
'extensionScannerIgnoreFile', 'extensionScannerIgnoreLine',
// static code analysis
'template', 'implements', 'extends'
];
$matches = [];
......
rules:
# - PHPStan\Rules\Arrays\AppendedArrayItemTypeRule
- PHPStan\Rules\Arrays\AppendedArrayItemTypeRule
- PHPStan\Rules\Arrays\IterableInForeachRule
- PHPStan\Rules\Arrays\OffsetAccessAssignmentRule
- PHPStan\Rules\Arrays\OffsetAccessAssignOpRule
......
......@@ -135,6 +135,7 @@ class Avatar
*/
protected function validateSortAndInitiateAvatarProviders()
{
/** @var array<string,array<mixed>> $providers */
$providers = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['backend']['avatarProviders'] ?? [];
if (empty($providers)) {
return;
......@@ -161,7 +162,9 @@ class Avatar
// Initializes providers
foreach ($orderedProviders as $configuration) {
$this->avatarProviders[] = GeneralUtility::makeInstance($configuration['provider']);
/** @var AvatarProviderInterface $avatarProvider */
$avatarProvider = GeneralUtility::makeInstance($configuration['provider']);
$this->avatarProviders[] = $avatarProvider;
}
}
......
......@@ -59,7 +59,7 @@ class InlineControlContainer extends AbstractContainer
protected $iconFactory;
/**
* @var string[]
* @var array<int,string|array<string,string>>
*/
protected $requireJsModules = [];
......
......@@ -31,6 +31,9 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* for output in frontend
*
* The AbstractRecordCollection uses SplDoublyLinkedList for internal storage
*
* @template T
* @implements RecordCollectionInterface<T>
*/
abstract class AbstractRecordCollection implements RecordCollectionInterface, PersistableCollectionInterface, SortableCollectionInterface
{
......
......@@ -22,6 +22,8 @@ namespace TYPO3\CMS\Core\Collection;
* of data values (f.e. strings, records, relations) in a
* common and generic way, while the class manages the storage
* in an appropriate way itself
*
* @template T
*/
interface CollectionInterface extends \Iterator, \Serializable, \Countable
{
......
......@@ -17,6 +17,9 @@ namespace TYPO3\CMS\Core\Collection;
/**
* Collection for handling records from a single database-table.
*
* @template T
* @extends CollectionInterface<T>
*/
interface RecordCollectionInterface extends CollectionInterface, NameableCollectionInterface
{
......
......@@ -52,10 +52,16 @@ class LinkService implements SingletonInterface
*/
public function __construct()
{
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['linkHandler'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['linkHandler'] as $type => $handler) {
$registeredLinkHandlers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['linkHandler'] ?? [];
$registeredLinkHandlers = is_array($registeredLinkHandlers) ? $registeredLinkHandlers : [];
/** @var array<string,class-string> $registeredLinkHandlers */
if ($registeredLinkHandlers !== []) {
foreach ($registeredLinkHandlers as $type => $handlerClassName) {
if (!isset($this->handlers[$type]) || !is_object($this->handlers[$type])) {
$this->handlers[$type] = GeneralUtility::makeInstance($handler);
$handler = GeneralUtility::makeInstance($handlerClassName);
if ($handler instanceof LinkHandlingInterface) {
$this->handlers[$type] = $handler;
}
}
}
}
......
......@@ -33,14 +33,14 @@ class ResourceMutex
/**
* Access lock
*
* @var LockingStrategyInterface[]
* @var array<string,LockingStrategyInterface|null>
*/
private $accessLocks = [];
/**
* Image processing lock
*
* @var LockingStrategyInterface[]
* @var array<string,LockingStrategyInterface|null>
*/
private $workerLocks = [];
......
......@@ -22,6 +22,7 @@ use TYPO3\CMS\Core\Resource\FileInterface;
/**
* Abstract collection.
* @extends AbstractRecordCollection<FileInterface>
*/
abstract class AbstractFileCollection extends AbstractRecordCollection
{
......
......@@ -38,7 +38,7 @@ use TYPO3\CMS\Core\Utility\PathUtility;
class ResourceFactory implements SingletonInterface
{
/**
* @var Collection\AbstractFileCollection[]
* @var array<int,CollectionInterface<File>>
*/
protected $collectionInstances = [];
......@@ -158,7 +158,7 @@ class ResourceFactory implements SingletonInterface
* Creates a collection object.
*
* @param array $collectionData The database row of the sys_file_collection record.
* @return Collection\AbstractFileCollection|CollectionInterface
* @return CollectionInterface<File>
*/
public function createCollectionObject(array $collectionData)
{
......
......@@ -3251,7 +3251,7 @@ class GeneralUtility
* registered implementations for this class
*
* @param string $className Base class name to evaluate
* @return string Final class name to instantiate with "new [classname]
* @return class-string Final class name to instantiate with "new [classname]
*/
protected static function getClassName($className)
{
......
......@@ -20,7 +20,6 @@ namespace TYPO3\CMS\Dashboard;
use Psr\Container\ContainerInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface;
use TYPO3\CMS\Dashboard\Widgets\WidgetInterface;
/**
* @internal
......@@ -38,7 +37,7 @@ class Dashboard
protected $title;
/**
* @var array
* @var array<string,array<string,string>>
*/
protected $widgetConfig;
......@@ -53,7 +52,7 @@ class Dashboard
protected $container;
/**
* @var WidgetInterface[]
* @var array<string,WidgetConfigurationInterface>
*/
protected $widgets = [];
......@@ -96,7 +95,7 @@ class Dashboard
}
/**
* @return WidgetInterface[]
* @return array<string,WidgetConfigurationInterface>
*/
public function getWidgets(): array
{
......@@ -111,7 +110,6 @@ class Dashboard
{
$availableWidgets = $this->widgetRegistry->getAvailableWidgets();
foreach ($this->widgetConfig as $hash => $widgetConfig) {
/* @var WidgetConfigurationInterface $widgetConfig */
if (array_key_exists($widgetConfig['identifier'], $availableWidgets)) {
$this->widgets[$hash] = $availableWidgets[$widgetConfig['identifier']];
}
......
......@@ -35,7 +35,7 @@ class WidgetRegistry implements SingletonInterface
protected $container;
/**
* @var WidgetConfigurationInterface[]
* @var array<string,WidgetConfigurationInterface>
*/
private $widgets = [];
......
......@@ -25,7 +25,7 @@ namespace TYPO3\CMS\Extensionmanager\Remote;
class RemoteRegistry
{
/**
* @var ExtensionDownloaderRemoteInterface[]
* @var array<string,array>
*/
protected $remotes = [];
......
......@@ -25,7 +25,7 @@ use TYPO3\CMS\Core\Html\HtmlParser;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Linkvalidator\Event\BeforeRecordIsAnalyzedEvent;
use TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype;
use TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface;
use TYPO3\CMS\Linkvalidator\Repository\BrokenLinkRepository;
/**
......@@ -66,7 +66,7 @@ class LinkAnalyzer
/**
* Array for hooks for own checks
*
* @var Linktype\AbstractLinktype[]
* @var LinktypeInterface[]
*/
protected $hookObjectsArr = [];
......@@ -109,7 +109,11 @@ class LinkAnalyzer
// Hook to handle own checks
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] ?? [] as $key => $className) {
$this->hookObjectsArr[$key] = GeneralUtility::makeInstance($className);
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof LinktypeInterface) {
continue;
}
$this->hookObjectsArr[$key] = $hookObject;
$options = $tsConfig['linktypesConfig.'][$key . '.'] ?? [];
// setAdditionalConfig might use global configuration, so still call it, even if options are empty
$this->hookObjectsArr[$key]->setAdditionalConfig($options);
......@@ -378,7 +382,6 @@ class LinkAnalyzer
continue;
}
/** @var AbstractLinktype $hookObj */
foreach ($this->hookObjectsArr as $keyArr => $hookObj) {
$type = $hookObj->fetchType($r, $type, $keyArr);
// Store the type that was found
......@@ -436,7 +439,6 @@ class LinkAnalyzer
}
$title = strip_tags($linkTags[$i]);
}
/** @var AbstractLinktype $hookObj */
foreach ($this->hookObjectsArr as $keyArr => $hookObj) {
$type = $hookObj->fetchType($currentR, $type, $keyArr);
// Store the type that was found
......
......@@ -345,7 +345,11 @@ class LinkValidatorReport
protected function initialize()
{
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] ?? [] as $linkType => $className) {
$this->hookObjectsArr[$linkType] = GeneralUtility::makeInstance($className);
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof LinktypeInterface) {
continue;
}
$this->hookObjectsArr[$linkType] = $hookObject;
}
$this->pageRecord = BackendUtility::readPageAccess($this->id, $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW));
......
......@@ -56,7 +56,7 @@ abstract class AbstractLinkBrowserController
protected $thisScript = '';
/**
* @var LinkHandlerInterface[]
* @var array<string,array>
*/
protected $linkHandlers = [];
......@@ -65,7 +65,7 @@ abstract class AbstractLinkBrowserController
*
* Comprised of url information and additional link parameters.
*
* @var string[]
* @var array<string,mixed>
*/
protected $currentLinkParts = [];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment