[TASK] Replace misused in_array calls 63/57463/4
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 4 Jul 2018 17:55:09 +0000 (19:55 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 6 Jul 2018 19:13:04 +0000 (21:13 +0200)
Resolves: #85474
Releases: master
Change-Id: I62b1fe0b5ea3e1b5340aa18c216c7491d2d64fad
Reviewed-on: https://review.typo3.org/57463
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: J├╝rgen Venne <venne@schaffrath-digital.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
25 files changed:
typo3/sysext/core/Classes/Integrity/DatabaseIntegrityCheck.php
typo3/sysext/core/Classes/Utility/RootlineUtility.php
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php
typo3/sysext/extbase/Tests/Functional/Persistence/RelationTest.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ArrayDimensionMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ArrayGlobalMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ClassConstantMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ClassNameMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ConstantMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/FunctionCallMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/InterfaceMethodChangedMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodArgumentDroppedMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodArgumentDroppedStaticMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodArgumentRequiredMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodArgumentRequiredStaticMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodArgumentUnusedMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodCallMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/MethodCallStaticMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/PropertyExistsStaticMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/PropertyProtectedMatcher.php
typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/PropertyPublicMatcher.php
typo3/sysext/install/Classes/Service/LanguagePackService.php
typo3/sysext/saltedpasswords/Classes/Utility/SaltedPasswordsUtility.php
typo3/sysext/workspaces/Classes/Controller/PreviewController.php
typo3/sysext/workspaces/Classes/Controller/ReviewController.php

index d636670..1ca8638 100644 (file)
@@ -480,7 +480,7 @@ class DatabaseIntegrityCheck
                                     $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
                                 )
                             );
-                        } elseif (in_array($fieldType, [Type::BLOB], true)) {
+                        } elseif ($fieldType === Type::BLOB) {
                             $whereClause[] = $queryBuilder->expr()->andX(
                                 $queryBuilder->expr()->isNotNull($fieldName),
                                 $queryBuilder->expr()
index 74d5ef5..bdac257 100644 (file)
@@ -421,7 +421,7 @@ class RootlineUtility
      */
     public function isMountedPage()
     {
-        return in_array($this->pageUid, array_keys($this->parsedMountPointParameters));
+        return array_key_exists($this->pageUid, $this->parsedMountPointParameters);
     }
 
     /**
index fb1c85e..ebf1002 100644 (file)
@@ -272,7 +272,7 @@ class DataMapper implements \TYPO3\CMS\Core\SingletonInterface
                         // $propertyValue = $this->mapArray($row[$columnName]); // Not supported, yet!
                         break;
                     case 'SplObjectStorage':
-                    case \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class:
+                    case Persistence\ObjectStorage::class:
                         $propertyValue = $this->mapResultToPropertyValue(
                             $object,
                             $propertyName,
@@ -353,7 +353,7 @@ class DataMapper implements \TYPO3\CMS\Core\SingletonInterface
     {
         $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
         if ($enableLazyLoading === true && $propertyMetaData['annotations']['lazy']) {
-            if ($propertyMetaData['type'] === \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) {
+            if ($propertyMetaData['type'] === Persistence\ObjectStorage::class) {
                 $result = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage::class, $parentObject, $propertyName, $fieldValue);
             } else {
                 if (empty($fieldValue)) {
@@ -549,14 +549,14 @@ class DataMapper implements \TYPO3\CMS\Core\SingletonInterface
             $propertyValue = $result;
         } else {
             $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
-            if (in_array($propertyMetaData['type'], ['array', 'ArrayObject', 'SplObjectStorage', \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class], true)) {
+            if (in_array($propertyMetaData['type'], ['array', 'ArrayObject', 'SplObjectStorage', Persistence\ObjectStorage::class], true)) {
                 $objects = [];
                 foreach ($result as $value) {
                     $objects[] = $value;
                 }
                 if ($propertyMetaData['type'] === 'ArrayObject') {
                     $propertyValue = new \ArrayObject($objects);
-                } elseif (in_array($propertyMetaData['type'], [\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class], true)) {
+                } elseif ($propertyMetaData['type'] === Persistence\ObjectStorage::class) {
                     $propertyValue = new Persistence\ObjectStorage();
                     foreach ($objects as $object) {
                         $propertyValue->attach($object);
index 266a7bd..0f5dc16 100644 (file)
@@ -1369,7 +1369,7 @@ class RelationTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTes
      */
     protected function countDistinctIds(array $ids)
     {
-        return count(array_count_values($ids));
+        return count(array_unique($ids));
     }
 
     /**
index 5c95b5e..c0de8d9 100644 (file)
@@ -49,7 +49,7 @@ class ArrayDimensionMatcher extends AbstractCoreMatcher
             && !$this->isLineIgnored($node)
             && $node instanceof ArrayDimFetch
             && isset($node->dim->value)
-            && in_array($node->dim->value, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->dim->value, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index b105f63..8312c36 100644 (file)
@@ -50,11 +50,7 @@ class ArrayGlobalMatcher extends AbstractCoreMatcher
             && $node->var instanceof Variable
             && $node->var->name === 'GLOBALS'
             && $node->dim instanceof String_
-            && in_array(
-                '$GLOBALS[\'' . $node->dim->value . '\']',
-                array_keys($this->matcherDefinitions),
-                true
-            )
+            && array_key_exists('$GLOBALS[\'' . $node->dim->value . '\']', $this->matcherDefinitions)
         ) {
             $this->matches[] = [
                 'restFiles' => $this->matcherDefinitions['$GLOBALS[\'' . $node->dim->value . '\']']['restFiles'],
index 7646486..d87e959 100644 (file)
@@ -48,7 +48,7 @@ class ClassConstantMatcher extends AbstractCoreMatcher
             && !$this->isLineIgnored($node)
             && $node instanceof ClassConstFetch
             && $node->class instanceof FullyQualified
-            && in_array($node->class->toString() . '::' . $node->name, array_keys($this->matcherDefinitions), true)
+            && array_key_exists($node->class->toString() . '::' . $node->name, $this->matcherDefinitions)
         ) {
             // No weak test implemented - combination class::const name tested
             $this->matches[] = [
index 69a59ac..ebe32d2 100644 (file)
@@ -46,7 +46,7 @@ class ClassNameMatcher extends AbstractCoreMatcher
             && $node instanceof FullyQualified
         ) {
             $fullyQualifiedClassName = $node->toString();
-            if (in_array($fullyQualifiedClassName, array_keys($this->matcherDefinitions), true)) {
+            if (array_key_exists($fullyQualifiedClassName, $this->matcherDefinitions)) {
                 $this->matches[] = [
                     'restFiles' => $this->matcherDefinitions[$fullyQualifiedClassName]['restFiles'],
                     'line' => $node->getAttribute('startLine'),
index e5d4c5d..dd51223 100644 (file)
@@ -46,7 +46,7 @@ class ConstantMatcher extends AbstractCoreMatcher
         if (!$this->isFileIgnored($node)
             && !$this->isLineIgnored($node)
             && $node instanceof ConstFetch
-            && in_array($node->name->toString(), array_keys($this->matcherDefinitions), true)
+            && array_key_exists($node->name->toString(), $this->matcherDefinitions)
         ) {
             // Access to constants is detected as strong match
             $this->matches[] = [
index fb13d1c..79ea6ce 100644 (file)
@@ -49,7 +49,7 @@ class FunctionCallMatcher extends AbstractCoreMatcher
             && !$this->isLineIgnored($node)
             && $node instanceof FuncCall
             && $node->name instanceof FullyQualified
-            && in_array($node->name->toString(), array_keys($this->matcherDefinitions), true)
+            && array_key_exists($node->name->toString(), $this->matcherDefinitions)
         ) {
             $functionName = $node->name->toString();
             $matchDefinition = $this->matcherDefinitions[$functionName];
index 1be9f71..02c114b 100644 (file)
@@ -58,7 +58,7 @@ class InterfaceMethodChangedMatcher extends AbstractCoreMatcher
 
         // Match method name of a class, must be public, wouldn't make sense as interface if protected/private
         if ($node instanceof ClassMethod
-            && in_array($node->name->name, array_keys($this->matcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->matcherDefinitions)
             && $node->flags & Class_::MODIFIER_PUBLIC // public
             && ($node->flags & Class_::MODIFIER_STATIC) !== Class_::MODIFIER_STATIC // not static
         ) {
@@ -80,7 +80,7 @@ class InterfaceMethodChangedMatcher extends AbstractCoreMatcher
 
         // Match method call (not static) with number of arguments
         if ($node instanceof MethodCall
-            && in_array($node->name->name, array_keys($this->matcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->matcherDefinitions)
         ) {
             $methodName = $node->name->name;
             $numberOfUsedArguments = 0;
index 82c9d24..3e47e9f 100644 (file)
@@ -50,7 +50,7 @@ class MethodArgumentDroppedMatcher extends AbstractCoreMatcher
         if (!$this->isFileIgnored($node)
             && !$this->isLineIgnored($node)
             && $node instanceof MethodCall
-            && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index 928df2d..7bad9db 100644 (file)
@@ -57,7 +57,7 @@ class MethodArgumentDroppedStaticMatcher extends AbstractCoreMatcher
                 // 'Foo\Bar::aMethod()' -> strong match
                 $fqdnClassWithMethod = $node->class->toString() . '::' . $node->name->name;
                 if (!$isArgumentUnpackingUsed
-                    && in_array($fqdnClassWithMethod, array_keys($this->matcherDefinitions), true)
+                    && array_key_exists($fqdnClassWithMethod, $this->matcherDefinitions)
                     && count($node->args) > $this->matcherDefinitions[$fqdnClassWithMethod]['maximumNumberOfArguments']
                 ) {
                     $this->matches[] = [
@@ -70,7 +70,7 @@ class MethodArgumentDroppedStaticMatcher extends AbstractCoreMatcher
                     ];
                 }
             } elseif ($node->class instanceof Variable
-                && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+                && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
             ) {
                 $match = [
                     'restFiles' => [],
index 9f168c6..904ae3e 100644 (file)
@@ -49,7 +49,7 @@ class MethodArgumentRequiredMatcher extends AbstractCoreMatcher
         if (!$this->isFileIgnored($node)
             && !$this->isLineIgnored($node)
             && $node instanceof MethodCall
-            && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index f3d732f..c40126b 100644 (file)
@@ -58,7 +58,7 @@ class MethodArgumentRequiredStaticMatcher extends AbstractCoreMatcher
                 $fqdnClassWithMethod = $node->class->toString() . '::' . $node->name->name;
                 $numberOfArguments = count($node->args);
                 if (!$isArgumentUnpackingUsed
-                    && in_array($fqdnClassWithMethod, array_keys($this->matcherDefinitions), true)
+                    && array_key_exists($fqdnClassWithMethod, $this->matcherDefinitions)
                     && $numberOfArguments < $this->matcherDefinitions[$fqdnClassWithMethod]['numberOfMandatoryArguments']
                     // maximum number of arguments is just a measure agains false positives
                     && $numberOfArguments <= $this->matcherDefinitions[$fqdnClassWithMethod]['maximumNumberOfArguments']
@@ -73,7 +73,7 @@ class MethodArgumentRequiredStaticMatcher extends AbstractCoreMatcher
                     ];
                 }
             } elseif ($node->class instanceof Variable
-                && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+                && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
             ) {
                 $match = [
                     'restFiles' => [],
index f9c494d..b410c89 100644 (file)
@@ -51,7 +51,7 @@ class MethodArgumentUnusedMatcher extends AbstractCoreMatcher
         if (!$this->isFileIgnored($node)
             && !$this->isLineIgnored($node)
             && $node instanceof MethodCall
-            && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index 0845a5b..bc08414 100644 (file)
@@ -49,7 +49,7 @@ class MethodCallMatcher extends AbstractCoreMatcher
         if (!$this->isFileIgnored($node)
             && !$this->isLineIgnored($node)
             && $node instanceof MethodCall
-            && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index 93bd5fd..b29767c 100644 (file)
@@ -62,7 +62,7 @@ class MethodCallStaticMatcher extends AbstractCoreMatcher
             if ($node->class instanceof FullyQualified) {
                 // 'Foo\Bar::deprecated()' -> strong match
                 $fqdnClassWithMethod = $node->class->toString() . '::' . $node->name->name;
-                if (in_array($fqdnClassWithMethod, array_keys($this->matcherDefinitions), true)) {
+                if (array_key_exists($fqdnClassWithMethod, $this->matcherDefinitions)) {
                     $this->matches[] = [
                         'restFiles' => $this->matcherDefinitions[$fqdnClassWithMethod]['restFiles'],
                         'line' => $node->getAttribute('startLine'),
@@ -71,7 +71,7 @@ class MethodCallStaticMatcher extends AbstractCoreMatcher
                     ];
                 }
             } elseif ($node->class instanceof Variable
-                && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+                && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
             ) {
                 $match = [
                     'restFiles' => [],
index 8f63237..7930193 100644 (file)
@@ -47,7 +47,7 @@ class PropertyExistsStaticMatcher extends AbstractCoreMatcher
             && $node instanceof Property
             && $node->isStatic()
             && !$node->isPrivate()
-            && in_array($node->props[0]->name->name, array_keys($this->matcherDefinitions), true)
+            && array_key_exists($node->props[0]->name->name, $this->matcherDefinitions)
         ) {
             $propertyName = $node->props[0]->name->name;
             $match = [
index b1e70c9..d40211a 100644 (file)
@@ -49,7 +49,7 @@ class PropertyProtectedMatcher extends AbstractCoreMatcher
             && $node instanceof PropertyFetch
             && $node->name instanceof Identifier
             && $node->var->name !== 'this'
-            && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index 7628b18..1412c35 100644 (file)
@@ -48,7 +48,7 @@ class PropertyPublicMatcher extends AbstractCoreMatcher
             && !$this->isLineIgnored($node)
             && $node instanceof PropertyFetch
             && $node->name instanceof Identifier
-            && in_array($node->name->name, array_keys($this->flatMatcherDefinitions), true)
+            && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
         ) {
             $match = [
                 'restFiles' => [],
index 002a8e1..58f5d52 100644 (file)
@@ -201,7 +201,7 @@ class LanguagePackService
         // Sanitize extension and iso code
         $availableLanguages = $this->getAvailableLanguages();
         $activeLanguages = $this->getActiveLanguages();
-        if (!in_array($iso, array_keys($availableLanguages), true) || !in_array($iso, $activeLanguages, true)) {
+        if (!array_key_exists($iso, $availableLanguages) || !in_array($iso, $activeLanguages, true)) {
             throw new \RuntimeException('Language iso code ' . (string)$iso . ' not available or active', 1520117054);
         }
         $packageManager = GeneralUtility::makeInstance(PackageManager::class);
index 1f2be3f..b58e432 100644 (file)
@@ -109,7 +109,10 @@ class SaltedPasswordsUtility
     {
         $extConf = self::returnExtConf($mode);
         $classNameToUse = \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class;
-        if (in_array($extConf['saltedPWHashingMethod'], array_keys(\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getRegisteredSaltedHashingMethods()))) {
+        if (array_key_exists(
+            $extConf['saltedPWHashingMethod'],
+            \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getRegisteredSaltedHashingMethods()
+        )) {
             $classNameToUse = $extConf['saltedPWHashingMethod'];
         }
         return $classNameToUse;
index c915738..2c8dca6 100644 (file)
@@ -131,7 +131,7 @@ class PreviewController
         list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
         $availableWorkspaces = $this->workspaceService->getAvailableWorkspaces();
         $activeWorkspace = $this->getBackendUser()->workspace;
-        if ($previewWS !== null && in_array($previewWS, array_keys($availableWorkspaces)) && $activeWorkspace != $previewWS) {
+        if ($previewWS !== null && array_key_exists($previewWS, $availableWorkspaces) && $activeWorkspace != $previewWS) {
             $activeWorkspace = $previewWS;
             $this->getBackendUser()->setWorkspace($activeWorkspace);
             BackendUtility::setUpdateSignal('updatePageTree');
index 58d80c6..cdbdc3c 100644 (file)
@@ -165,7 +165,7 @@ class ReviewController extends ActionController
         } else {
             if ((string)GeneralUtility::_GP('workspace') !== '') {
                 $switchWs = (int)GeneralUtility::_GP('workspace');
-                if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) {
+                if (array_key_exists($switchWs, $wsList) && $activeWorkspace != $switchWs) {
                     $activeWorkspace = $switchWs;
                     $backendUser->setWorkspace($activeWorkspace);
                     $performWorkspaceSwitch = true;