Skip to content

Commit

Permalink
Merge pull request #10891 from josephwynn-sc/json-serialize-should-be…
Browse files Browse the repository at this point in the history
…-ignored

Ignore jsonSerialize for implementors of JsonSerializable
  • Loading branch information
orklah committed Apr 28, 2024
2 parents 81e4b97 + 98ecec6 commit 8fcb6b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,12 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth
continue;
}

if ($codebase->classImplements($classlike_storage->name, 'JsonSerializable')
&& ($method_name === 'jsonserialize')
) {
continue;
}

$has_variable_calls = $codebase->analyzer->hasMixedMemberName($method_name)
|| $codebase->analyzer->hasMixedMemberName(strtolower($classlike_storage->name . '::'));

Expand Down
10 changes: 10 additions & 0 deletions tests/UnusedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,16 @@ function getArg(string $method) : void {
}
}',
],
'ignoreJsonSerialize' => [
'code' => '<?php
class Foo implements JsonSerializable {
public function jsonSerialize() : array {
return [];
}
}
new Foo();',
],
'ignoreSerializerSerialize' => [
'code' => '<?php
class Foo implements Serializable {
Expand Down

0 comments on commit 8fcb6b4

Please sign in to comment.