Skip to content

Commit 1029bba

Browse files
VincentLangletondrejmirtes
authored andcommitted
Compute allowedArrayType only once
1 parent c47c304 commit 1029bba

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Rules/Arrays/InvalidKeyInArrayDimFetchRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ public function processNode(Node $node, Scope $scope): array
5858
return [];
5959
}
6060

61-
$phpVersion = $this->phpVersion;
61+
$allowedArrayKeys = AllowedArrayKeysTypes::getType($this->phpVersion);
6262
$dimensionType = $this->ruleLevelHelper->findTypeToCheck(
6363
$scope,
6464
$node->dim,
6565
'',
66-
static fn (Type $dimType): bool => AllowedArrayKeysTypes::getType($phpVersion)->isSuperTypeOf($dimType)->yes(),
66+
static fn (Type $dimType): bool => $allowedArrayKeys->isSuperTypeOf($dimType)->yes(),
6767
)->getType();
6868
if ($dimensionType instanceof ErrorType) {
6969
return [];
7070
}
7171

72-
$isSuperType = AllowedArrayKeysTypes::getType($phpVersion)->isSuperTypeOf($dimensionType);
72+
$isSuperType = $allowedArrayKeys->isSuperTypeOf($dimensionType);
7373
if ($isSuperType->yes() || ($isSuperType->maybe() && !$this->reportMaybes)) {
7474
return [];
7575
}

src/Rules/Arrays/InvalidKeyInArrayItemRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ public function processNode(Node $node, Scope $scope): array
3939
return [];
4040
}
4141

42-
$phpVersion = $this->phpVersion;
42+
$allowedArrayKeys = AllowedArrayKeysTypes::getType($this->phpVersion);
4343
$dimensionType = $this->ruleLevelHelper->findTypeToCheck(
4444
$scope,
4545
$node->key,
4646
'',
47-
static fn (Type $dimType): bool => AllowedArrayKeysTypes::getType($phpVersion)->isSuperTypeOf($dimType)->yes(),
47+
static fn (Type $dimType): bool => $allowedArrayKeys->isSuperTypeOf($dimType)->yes(),
4848
)->getType();
4949
if ($dimensionType instanceof ErrorType) {
5050
return [];
5151
}
5252

53-
$isSuperType = AllowedArrayKeysTypes::getType($phpVersion)->isSuperTypeOf($dimensionType);
53+
$isSuperType = $allowedArrayKeys->isSuperTypeOf($dimensionType);
5454
if ($isSuperType->yes()) {
5555
return [];
5656
}

0 commit comments

Comments
 (0)