Skip to content

Conversation

@arshidkv12
Copy link
Contributor

No description provided.

*/
public function getNodeTypes(): array
{
return [Class_::class, Trait_::class];
Copy link
Member

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 */'));
Copy link
Member

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

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) {
Copy link
Member

Choose a reason for hiding this comment

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

use ->isPromoted()

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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 ?

Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class Fixture
class SkipFixtureReadonly

Copy link
Member

@samsonasik samsonasik left a 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:

@samsonasik
Copy link
Member

Please add fixture I requested above #317 (review) and run rector and fix-cs

vendor/bin/rector && composer fix-cs

@arshidkv12
Copy link
Contributor Author

Please check it.

@samsonasik
Copy link
Member

Please add fixture for implicit public I requested above

#317 (review)

@samsonasik
Copy link
Member

Thank you @arshidkv12 , I've added $hasChanged check flag to verify node is changed.

@samsonasik samsonasik merged commit 968f660 into rectorphp:main Sep 8, 2025
6 checks passed
@@ -0,0 +1,25 @@
<?php
Copy link
Member

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 ...

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants