Skip to content

Commit 49a6bef

Browse files
Rename
1 parent 89f4394 commit 49a6bef

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

conf/config.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ parameters:
7676
reportStaticMethodSignatures: false
7777
reportWrongPhpDocTypeInVarTag: false
7878
reportAnyTypeWideningInVarTag: false
79-
reportArrayKeyCast: false
79+
allowFloatBoolNullAsArrayKey: true
8080
reportPossiblyNonexistentGeneralArrayOffset: false
8181
reportPossiblyNonexistentConstantArrayOffset: false
8282
checkMissingOverrideMethodAttribute: false

conf/parametersSchema.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ parametersSchema:
8585
reportStaticMethodSignatures: bool()
8686
reportWrongPhpDocTypeInVarTag: bool()
8787
reportAnyTypeWideningInVarTag: bool()
88-
reportArrayKeyCast: bool()
88+
allowFloatBoolNullAsArrayKey: bool()
8989
reportPossiblyNonexistentGeneralArrayOffset: bool()
9090
reportPossiblyNonexistentConstantArrayOffset: bool()
9191
checkMissingOverrideMethodAttribute: bool()

src/Rules/Arrays/AllowedArrayKeysTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
final class AllowedArrayKeysTypes
2323
{
2424

25-
public static function getType(?PhpVersion $phpVersion = null, bool $strict = false): Type
25+
public static function getType(?PhpVersion $phpVersion = null, bool $allowFloatBoolNull = true): Type
2626
{
2727
$types = [
2828
new IntegerType(),
2929
new StringType(),
3030
];
3131

32-
if (!$strict) {
32+
if (!$allowFloatBoolNull) {
3333
$types[] = new BooleanType();
3434

3535
if ($phpVersion === null || !$phpVersion->deprecatesImplicitlyFloatConversionToInt()) {

src/Rules/Arrays/InvalidKeyInArrayDimFetchRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
#[AutowiredParameter]
2929
private bool $reportMaybes,
3030
#[AutowiredParameter]
31-
private bool $reportArrayKeyCast,
31+
private bool $allowFloatBoolNullAsArrayKey,
3232
)
3333
{
3434
}
@@ -61,18 +61,18 @@ public function processNode(Node $node, Scope $scope): array
6161
}
6262

6363
$phpVersion = $this->phpVersion;
64-
$reportArrayKeyCast = $this->reportArrayKeyCast;
64+
$allowFloatBoolNullAsArrayKey = $this->allowFloatBoolNullAsArrayKey;
6565
$dimensionType = $this->ruleLevelHelper->findTypeToCheck(
6666
$scope,
6767
$node->dim,
6868
'',
69-
static fn (Type $dimType): bool => AllowedArrayKeysTypes::getType($phpVersion, $reportArrayKeyCast)->isSuperTypeOf($dimType)->yes(),
69+
static fn (Type $dimType): bool => AllowedArrayKeysTypes::getType($phpVersion, $allowFloatBoolNullAsArrayKey)->isSuperTypeOf($dimType)->yes(),
7070
)->getType();
7171
if ($dimensionType instanceof ErrorType) {
7272
return [];
7373
}
7474

75-
$isSuperType = AllowedArrayKeysTypes::getType($phpVersion, $reportArrayKeyCast)->isSuperTypeOf($dimensionType);
75+
$isSuperType = AllowedArrayKeysTypes::getType($phpVersion, $allowFloatBoolNullAsArrayKey)->isSuperTypeOf($dimensionType);
7676
if ($isSuperType->yes() || ($isSuperType->maybe() && !$this->reportMaybes)) {
7777
return [];
7878
}

src/Rules/Arrays/InvalidKeyInArrayItemRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
private RuleLevelHelper $ruleLevelHelper,
2727
private PhpVersion $phpVersion,
2828
#[AutowiredParameter]
29-
private bool $reportArrayKeyCast,
29+
private bool $allowFloatBoolNullAsArrayKey,
3030
)
3131
{
3232
}
@@ -43,18 +43,18 @@ public function processNode(Node $node, Scope $scope): array
4343
}
4444

4545
$phpVersion = $this->phpVersion;
46-
$reportArrayKeyCast = $this->reportArrayKeyCast;
46+
$allowFloatBoolNullAsArrayKey = $this->allowFloatBoolNullAsArrayKey;
4747
$dimensionType = $this->ruleLevelHelper->findTypeToCheck(
4848
$scope,
4949
$node->key,
5050
'',
51-
static fn (Type $dimType): bool => AllowedArrayKeysTypes::getType($phpVersion, $reportArrayKeyCast)->isSuperTypeOf($dimType)->yes(),
51+
static fn (Type $dimType): bool => AllowedArrayKeysTypes::getType($phpVersion, $allowFloatBoolNullAsArrayKey)->isSuperTypeOf($dimType)->yes(),
5252
)->getType();
5353
if ($dimensionType instanceof ErrorType) {
5454
return [];
5555
}
5656

57-
$isSuperType = AllowedArrayKeysTypes::getType($phpVersion, $reportArrayKeyCast)->isSuperTypeOf($dimensionType);
57+
$isSuperType = AllowedArrayKeysTypes::getType($phpVersion, $allowFloatBoolNullAsArrayKey)->isSuperTypeOf($dimensionType);
5858
if ($isSuperType->yes()) {
5959
return [];
6060
}

tests/PHPStan/Rules/Arrays/InvalidKeyInArrayDimFetchRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class InvalidKeyInArrayDimFetchRuleTest extends RuleTestCase
1616
{
1717

18-
private bool $reportCastedArrayKey = false;
18+
private bool $allowFloatBoolNullAsArrayKey = true;
1919

2020
protected function getRule(): Rule
2121
{
@@ -24,7 +24,7 @@ protected function getRule(): Rule
2424
$ruleLevelHelper,
2525
self::getContainer()->getByType(PhpVersion::class),
2626
true,
27-
$this->reportCastedArrayKey,
27+
$this->allowFloatBoolNullAsArrayKey,
2828
);
2929
}
3030

@@ -168,7 +168,7 @@ public function testBug12981(): void
168168

169169
public function testUnsetFalseKey(): void
170170
{
171-
$this->reportCastedArrayKey = true;
171+
$this->allowFloatBoolNullAsArrayKey = false;
172172

173173
$this->analyse([__DIR__ . '/data/unset-false-key.php'], [
174174
[

tests/PHPStan/Rules/Arrays/InvalidKeyInArrayItemRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class InvalidKeyInArrayItemRuleTest extends RuleTestCase
1616
{
1717

18-
private bool $reportCastedArrayKey = false;
18+
private bool $allowFloatBoolNullAsArrayKey = true;
1919

2020
private bool $checkExplicitMixed = false;
2121

@@ -28,7 +28,7 @@ protected function getRule(): Rule
2828
return new InvalidKeyInArrayItemRule(
2929
$ruleLevelHelper,
3030
self::getContainer()->getByType(PhpVersion::class),
31-
$this->reportCastedArrayKey,
31+
$this->allowFloatBoolNullAsArrayKey,
3232
);
3333
}
3434

@@ -107,7 +107,7 @@ public function testInvalidMixedKey(): void
107107

108108
public function testInvalidKeyReportingCastedArrayKey(): void
109109
{
110-
$this->reportCastedArrayKey = true;
110+
$this->allowFloatBoolNullAsArrayKey = false;
111111

112112
$this->analyse([__DIR__ . '/data/invalid-key-array-item.php'], [
113113
[

0 commit comments

Comments
 (0)