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

Support @immutable phpdoc in RestoreDefaultNullToNullableTypePropertyRector #5795

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Apr 3, 2024

RestoreDefaultNullToNullableTypePropertyRector already supports a @readonly property-level phpdoc. therefore I figured it should also support the class level @immutable which is equivalent to the native readonly class-level keyword


/**
* @immutable
*/
Copy link
Member

@samsonasik samsonasik Apr 3, 2024

Choose a reason for hiding this comment

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

I never use Immutable attribute, but found in a project, is it possible to skip:

#[\JetBrains\PhpStorm\Immutable]

and is that correct to skip that as well?

Copy link
Contributor Author

@staabm staabm Apr 3, 2024

Choose a reason for hiding this comment

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

my motivation to skip the phpdoc attribute is related to it beeing supported by phpstan.
(the rector rule when applied on classes tagged with @immutable will result in phpstan errors)

the jetbrains annotation is not supported by phpstan AFAIK, therefore not part of this PR.

I think it would be correct to support it in rector, if/when phpstan supports it

@samsonasik samsonasik merged commit 3f1ccb3 into rectorphp:main Apr 3, 2024
39 checks passed
@samsonasik
Copy link
Member

Thank you @staabm

@staabm staabm deleted the immu branch April 3, 2024 11:20

// @immutable annotation
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);
$tags = $phpDocInfo->getTagsByName('@immutable');
Copy link
Member

Choose a reason for hiding this comment

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

I am on mobile, hasByName() should actually can be used

public function hasByName(string $name): bool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here you are: #5797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants