Commit bcf02891 authored by Wouter Wolters's avatar Wouter Wolters Committed by Anja Leichsenring
Browse files

[TASK] Replace misused in_array calls

Resolves: #85474
Releases: master
Change-Id: I62b1fe0b5ea3e1b5340aa18c216c7491d2d64fad
Reviewed-on: https://review.typo3.org/57463


Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Jürgen Venne's avatarJürgen Venne <venne@schaffrath-digital.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent bf4bfb79
......@@ -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()
......
......@@ -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);
}
/**
......
......@@ -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);
......
......@@ -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));
}
/**
......
......@@ -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' => [],
......
......@@ -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'],
......
......@@ -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[] = [
......
......@@ -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'),
......
......@@ -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[] = [
......
......@@ -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];
......
......@@ -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;
......
......@@ -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' => [],
......
......@@ -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' => [],
......
......@@ -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' => [],
......
......@@ -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' => [],
......
......@@ -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' => [],
......
......@@ -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' => [],
......
......@@ -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' => [],
......
......@@ -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 = [
......
......@@ -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' => [],
......
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