Skip to content

Commit 2066a7e

Browse files
VincentLangletondrejmirtes
authored andcommitted
Avoid false-positive Offset does not exist on via isset
1 parent 6367eb6 commit 2066a7e

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static function (Type $type) use ($dimType): bool {
8585
}
8686
}
8787

88-
if ($report) {
88+
if (!$scope->isInExpressionAssign($var) && $report) {
8989
return [
9090
RuleErrorBuilder::message(sprintf('Offset %s does not exist on %s.', $dimType->describe(VerbosityLevel::value()), $type->describe(VerbosityLevel::value())))->build(),
9191
];

tests/PHPStan/Rules/Arrays/data/nonexistent-offset.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,18 @@ public function doFoo(): void
444444
}
445445

446446
}
447+
448+
class Bug3282
449+
{
450+
/**
451+
* @phpstan-param array{event: string, msg?: array{ts?: int}} $array
452+
*/
453+
public function foo(array $array): int
454+
{
455+
if (isset($array['msg']['ts'])) {
456+
return 1;
457+
}
458+
459+
return 0;
460+
}
461+
}

0 commit comments

Comments
 (0)