Skip to content

VisibilityManipulator adjustment#1362

Merged
TomasVotruba merged 4 commits intorectorphp:mainfrom
Bl00D4NGEL:visibility-manipulator-static-fix
Dec 2, 2021
Merged

VisibilityManipulator adjustment#1362
TomasVotruba merged 4 commits intorectorphp:mainfrom
Bl00D4NGEL:visibility-manipulator-static-fix

Conversation

@Bl00D4NGEL
Copy link
Copy Markdown

Previously the VisibilityManipulator would strip public, protected and/or private visibility. This caused the ChangeMethodVisibilityRector to cause problems described in rectorphp/rector#6829

refs: rectorphp/rector#6829
closes: rectorphp/rector#6829

@Bl00D4NGEL
Copy link
Copy Markdown
Author

@TomasVotruba please review. My changes don't seem to be the cause for the rector-nette step to fail. :)


if ($isStatic) {
$this->makeStatic($node);
$this->addVisibilityFlag($node, Visibility::STATIC);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change? Now we have to maintain the same code on 2 places, which might lead to change of one without another.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I just tried to be as close to the previous code as possible without breaking other functionality.
We need to apparently strip the static tag so the visibility is correctly adjusted. (If I would not strip it other tests are failing)
What do you exactly mean by "maintain the same coe on 2 places"? Maybe I can find a way to improve this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code seems 100 % same as in makeStatic().

What do you exactly mean by "maintain the same coe on 2 places"? Maybe I can find a way to improve this.

If there is bug in makeStatic(), now we have to fix in 2 places.
How does this fix the reported bug?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I honestly copied from makeStatic and forgot that I did that when trying to look for the solution 😅 Adjusted the calls to use the makeStatic and makeNonStatic functions instead.

Previously we were removing the visibility modifier (which I don't quite understand why) because it somehow fixed rectorphp/rector#4941 in rectorphp/rector#4951 but it looks like this change is actually the only one required to fix the problem listed in rectorphp/rector#6829.
I didn't dig deep enough to find out why this is the case though.

Comment thread rules/Privatization/NodeManipulator/VisibilityManipulator.php Outdated
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you for the test and fix 👏 amazing work.

I'll check why the Nette package fails, last PRs today it was working fine.

@TomasVotruba
Copy link
Copy Markdown
Member

Could you rebase on current main? I tried to cleanup package testing CI setup

@Bl00D4NGEL Bl00D4NGEL force-pushed the visibility-manipulator-static-fix branch from 8d15fe6 to 962eb3f Compare December 1, 2021 20:36
@TomasVotruba TomasVotruba merged commit 3f07f38 into rectorphp:main Dec 2, 2021
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you, this looks solid 🤗

@Bl00D4NGEL Bl00D4NGEL deleted the visibility-manipulator-static-fix branch December 2, 2021 11:05
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.

Incorrect behavior of ChangeMethodVisibilityRector

3 participants