Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid false-positive Offset does not exist on via isset
  • Loading branch information
VincentLanglet committed Feb 16, 2021
commit f1f10a729e93c37f8595b8d686a7387bda42fcf5
2 changes: 1 addition & 1 deletion src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static function (Type $type) use ($dimType): bool {
}
}

if ($report) {
if (!$scope->isInExpressionAssign($var) && $report) {
return [
RuleErrorBuilder::message(sprintf('Offset %s does not exist on %s.', $dimType->describe(VerbosityLevel::value()), $type->describe(VerbosityLevel::value())))->build(),
];
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/nonexistent-offset.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,18 @@ public function doFoo(): void
}

}

class Bug3282
{
/**
* @phpstan-param array{event: string, msg?: array{ts?: int}} $array
*/
public function foo(array $array): int
{
if (isset($array['msg']['ts'])) {
return 1;
}

return 0;
}
}