Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Oct 10, 2025

Prefer known class, over pseudo-dynamic value:

final class AllowOverride
{
    public function run(KnownClass $classWithConstants)
    {
-        return $classWithConstants::SOME_CONSTANT;
+        return KnownClass::SOME_CONSTANT;
    }
}

@TomasVotruba TomasVotruba force-pushed the tv-variable-const-fetch-to-class-const-fetch branch from 9c5b838 to c6de4a5 Compare October 10, 2025 12:56
@TomasVotruba TomasVotruba changed the title tv variable const fetch to class const fetch [code-quality] Add VariableConstFetchToClassConstFetchRector Oct 10, 2025
@TomasVotruba TomasVotruba force-pushed the tv-variable-const-fetch-to-class-const-fetch branch 2 times, most recently from 481eee4 to 4cc11c6 Compare October 10, 2025 12:57
@TomasVotruba TomasVotruba force-pushed the tv-variable-const-fetch-to-class-const-fetch branch from 4cc11c6 to 36b2cf4 Compare October 10, 2025 14:47
@TomasVotruba TomasVotruba enabled auto-merge (squash) October 10, 2025 14:48
@TomasVotruba TomasVotruba merged commit 1d7a05f into main Oct 10, 2025
50 checks passed
@TomasVotruba TomasVotruba deleted the tv-variable-const-fetch-to-class-const-fetch branch October 10, 2025 14:56
*/
public function refactor(Node $node): ?ClassConstFetch
{
if (! $node->class instanceof Expr) {
Copy link
Member

Choose a reason for hiding this comment

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

per rule name, I think this needs to be exactly check against Variable node, check on Expr may cause invalid due to side effect call, eg:

some_side_effect()::NAME;

see https://3v4l.org/UkiYR

I will create new PR to fix it.

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.

3 participants