Skip to content

Commit 38582a3

Browse files
committed
1 parent 95f8a11 commit 38582a3

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/Rules/Playground/ArrayDimCastRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function processNode(Node $node, Scope $scope): array
5353
$arrayKeyType->describe(VerbosityLevel::value()),
5454
$arrayKeyType->describe(VerbosityLevel::typeOnly()),
5555
))->identifier('phpstanPlayground.arrayDimFetchCast')
56+
->tip('Learn more: <fg=cyan>https://phpstan.org/blog/why-array-string-keys-are-not-type-safe</>')
5657
->build();
5758
}
5859

src/Rules/Playground/LiteralArrayKeyCastRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function processNode(Node $node, Scope $scope): array
4949
$arrayKeyType->describe(VerbosityLevel::value()),
5050
$arrayKeyType->describe(VerbosityLevel::typeOnly()),
5151
))->identifier('phpstanPlayground.arrayKeyCast')
52+
->tip('Learn more: <fg=cyan>https://phpstan.org/blog/why-array-string-keys-are-not-type-safe</>')
5253
->line($item->getStartLine())
5354
->build();
5455
}

tests/PHPStan/Rules/Playground/ArrayDimCastRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,42 @@ protected function getRule(): Rule
1818

1919
public function testRule(): void
2020
{
21+
$tip = 'Learn more: <fg=cyan>https://phpstan.org/blog/why-array-string-keys-are-not-type-safe</>';
2122
$this->analyse([__DIR__ . '/data/array-dim-fetch-cast.php'], [
2223
[
2324
"Key '1' (string) will be cast to 1 (int) in the array access.",
2425
13,
26+
$tip,
2527
],
2628
[
2729
"Key null (null) will be cast to '' (string) in the array access.",
2830
14,
31+
$tip,
2932
],
3033
[
3134
'Key 2.5 (float) will be cast to 2 (int) in the array access.',
3235
15,
36+
$tip,
3337
],
3438
[
3539
'Key true (bool) will be cast to 1 (int) in the array access.',
3640
17,
41+
$tip,
3742
],
3843
[
3944
'Key false (bool) will be cast to 0 (int) in the array access.',
4045
18,
46+
$tip,
4147
],
4248
[
4349
"Key '10' (string) will be cast to 10 (int) in the array access.",
4450
20,
51+
$tip,
4552
],
4653
[
4754
"Key '1' (string) will be cast to 1 (int) in the array access.",
4855
26,
56+
$tip,
4957
],
5058
]);
5159
}

tests/PHPStan/Rules/Playground/LiteralArrayKeyCastRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,37 @@ protected function getRule(): Rule
1818

1919
public function testRule(): void
2020
{
21+
$tip = 'Learn more: <fg=cyan>https://phpstan.org/blog/why-array-string-keys-are-not-type-safe</>';
2122
$this->analyse([__DIR__ . '/data/literal-array-key-cast.php'], [
2223
[
2324
"Key '1' (string) will be cast to 1 (int) in the array.",
2425
14,
26+
$tip,
2527
],
2628
[
2729
"Key null (null) will be cast to '' (string) in the array.",
2830
15,
31+
$tip,
2932
],
3033
[
3134
'Key 2.5 (float) will be cast to 2 (int) in the array.',
3235
16,
36+
$tip,
3337
],
3438
[
3539
'Key true (bool) will be cast to 1 (int) in the array.',
3640
18,
41+
$tip,
3742
],
3843
[
3944
'Key false (bool) will be cast to 0 (int) in the array.',
4045
19,
46+
$tip,
4147
],
4248
[
4349
"Key '10' (string) will be cast to 10 (int) in the array.",
4450
21,
51+
$tip,
4552
],
4653
]);
4754
}

0 commit comments

Comments
 (0)