Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Override attribute #10493

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stubs/CoreGenericAttributes.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ final class AllowDynamicProperties
public function __construct() {}
}

#[Attribute(Attribute::TARGET_METHOD)]
final class Override
{
public function __construct() {}
}

#[Attribute(Attribute::TARGET_PARAMETER)]
final class SensitiveParameter
{
Expand Down
16 changes: 16 additions & 0 deletions tests/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ class Foo
'ignored_issues' => [],
'php_version' => '8.2',
],
'override' => [
'code' => '<?php

namespace OverrideAttribute;

use Override;

class HelloWorld {
#[Override]
public function __invoke() {}
}
Comment on lines +303 to +306
Copy link
Contributor

@tscni tscni Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi, this is code that should actually error, because there's no parent method to override.

Not that it matters much of course. Once real support for Override is added, this test case just needs to be corrected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are completely right. However, this particular piece of code would throw a PHP fatal error (i.e. HelloWorld::__invoke() has #[\Override] attribute, but no matching parent method exists) - not a psalm error per se. The PR, as is, creates the #[Override] core attribute so that psalm does not throw an InvalidAttribute error. That being said, I am happy to fix this if the maintainers agree on doing so - I definitely think it is a good idea.

',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'sensitiveParameter' => [
'code' => '<?php

Expand Down
Loading