Skip to content

Commit

Permalink
Merge pull request #10858 from edsrzf/handle-stringable-override
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Mar 25, 2024
2 parents fb7278e + 6269b80 commit dee88f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,8 @@ private function getFunctionInformation(
&& $codebase->config->ensure_override_attribute
&& $overridden_method_ids
&& $storage->cased_name !== '__construct'
&& ($storage->cased_name !== '__toString'
|| isset($appearing_class_storage->direct_class_interfaces['stringable']))
) {
IssueBuffer::maybeAdd(
new MissingOverrideAttribute(
Expand Down
26 changes: 26 additions & 0 deletions tests/OverrideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ public function f(): void {}
'ignored_issues' => [],
'php_version' => '8.3',
],
'ignoreImplicitStringable' => [
'code' => '
<?php
class A {
public function __toString(): string {
return "";
}
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
];
}

Expand Down Expand Up @@ -190,6 +203,19 @@ public function f(): void;
'error_levels' => [],
'php_version' => '8.3',
],
'explicitStringable' => [
'code' => '
<?php
class A implements Stringable {
public function __toString(): string {
return "";
}
}
',
'error_message' => 'MissingOverrideAttribute',
'error_levels' => [],
'php_version' => '8.3',
],
];
}
}

0 comments on commit dee88f5

Please sign in to comment.