Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Make array access on possible false tolerant with isset" #3043

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Rules/Arrays/NonexistentOffsetInArrayDimFetchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ public function processNode(Node $node, Scope $scope): array

$isOffsetAccessible = $isOffsetAccessibleType->isOffsetAccessible();

if ($scope->isInExpressionAssign($node) && $isOffsetAccessible->yes()) {
return [];
}

if ($scope->isUndefinedExpressionAllowed($node) && !$isOffsetAccessible->no()) {
if (($scope->isInExpressionAssign($node) || $scope->isUndefinedExpressionAllowed($node)) && $isOffsetAccessible->yes()) {
return [];
}

Expand Down
7 changes: 6 additions & 1 deletion tests/PHPStan/Levels/data/arrayDimFetches-7.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@
"message": "Cannot access offset 'foo' on iterable<int|string, object>.",
"line": 58,
"ignorable": true
},
{
"message": "Cannot access offset 'foo' on iterable<int|string, object>.",
"line": 66,
"ignorable": true
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public function testRule(): void
'Cannot access offset \'a\' on Closure(): void.',
253,
],
[
'Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void).',
258,
],
[
'Offset string does not exist on array<int, string>.',
308,
Expand Down Expand Up @@ -534,14 +538,4 @@ public function testBug8097(): void
$this->analyse([__DIR__ . '/data/bug-8097.php'], []);
}

public function testBug8068(): void
{
$this->analyse([__DIR__ . '/data/bug-8068.php'], [
[
"Cannot access offset 'path' on Closure.",
18,
],
]);
}

}
28 changes: 0 additions & 28 deletions tests/PHPStan/Rules/Arrays/data/bug-8068.php

This file was deleted.

Loading