-
Notifications
You must be signed in to change notification settings - Fork 24
DowngradeFinalPropertyPromotionRector #317
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
Conversation
| */ | ||
| public function getNodeTypes(): array | ||
| { | ||
| return [Class_::class, Trait_::class]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Node\Stmt\ClassMethod
|
|
||
| $existingDoc = $promotedParam->getDocComment(); | ||
| if (! $existingDoc) { | ||
| $promotedParam->setDocComment(new Doc('/** @final */')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use docblockUpdater instead, ensure existing doc when exists not removed, see example
rector-downgrade-php/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php
Lines 131 to 142 in 8ab1dce
| private function addPhpDocTag(Property|Param $node): bool | |
| { | |
| $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); | |
| if ($phpDocInfo->hasByName(self::TAGNAME)) { | |
| return false; | |
| } | |
| $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@' . self::TAGNAME, new GenericTagValueNode(''))); | |
| $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); | |
| return true; | |
| } |
| } | ||
|
|
||
| foreach ($constructorClassMethod->params as $promotedParam) { | ||
| if (($promotedParam->flags & Modifiers::FINAL) !== 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ->isPromoted()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use VisibilityManipulator->hasVisibility() as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(!$this->visibilityManipulator->hasVisibility($param, Visibility::PUBLIC)){
continue;
}Correct ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visibility::FINAL
|
|
||
| foreach ($constructorClassMethod->params as $promotedParam) { | ||
| if (($promotedParam->flags & Modifiers::FINAL) !== 0) { | ||
| $promotedParam->flags &= ~Modifiers::FINAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use VisibilityManipulator->makeNonFinal() usage, see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The makeNonFinal method is accepting Class_|ClassMethod, not accepting param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should add Param as well on rector-src then
|
|
||
| namespace Rector\Tests\DowngradeFinalPropertyPromotionRector\Rector\Class_\DowngradePropertyPromotionRector\Fixture; | ||
|
|
||
| class Fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| class Fixture | |
| class SkipFixtureReadonly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably consider implicit property promotion fixture as well:
class ImplicitFinalPropertyPromotion
{
- public function __construct(final string $foo)
+ public function __construct(
+ /**
+ * @final
+ */
+ public string $foo
)
{
}
}https://3v4l.org/BXcO6/rfc#vgit.master
However, this probably a "bug" in php 8.5 which without explicit public, it can't be accessed even it should means a public, see the different:
- https://3v4l.org/TdZfV/rfc#vgit.master (explicit)
- https://3v4l.org/LMaT0/rfc#vgit.master (implicit)
|
Please add fixture I requested above #317 (review) and run rector and fix-cs |
|
Please check it. |
|
Please add fixture for implicit public I requested above |
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp85/Rector/Class_/DowngradeFinalPropertyPromotionRector.php
Show resolved
Hide resolved
|
Thank you @arshidkv12 , I've added |
| @@ -0,0 +1,25 @@ | |||
| <?php | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arshidkv12 oh, this is .php file, and skipped from the scan, should be .php.inc, I was wondering why it was working ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.