1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Merge pull request #10858 from edsrzf/handle-stringable-override

This commit is contained in:
Bruce Weirdan 2024-03-25 23:04:45 +01:00 committed by GitHub
commit dee88f5a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -1996,6 +1996,8 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
&& $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(

View File

@ -85,6 +85,19 @@ class OverrideTest extends TestCase
'ignored_issues' => [],
'php_version' => '8.3',
],
'ignoreImplicitStringable' => [
'code' => '
<?php
class A {
public function __toString(): string {
return "";
}
}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
];
}
@ -190,6 +203,19 @@ class OverrideTest extends TestCase
'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',
],
];
}
}