Skip to content

Conversation

@samsonasik
Copy link
Member

Avoid on NodeTypeResolver to avoid on purpose string on php 8.x on type declaration set.

Let's do per use case fix.

@samsonasik samsonasik enabled auto-merge (squash) October 8, 2025 05:16
@samsonasik samsonasik merged commit 15d2df3 into main Oct 8, 2025
50 checks passed
@samsonasik samsonasik deleted the apply-type branch October 8, 2025 05:17
&& $this->isName($node->expr, 'substr')
&& ! $node->expr->isFirstClassCallable()) {
$nodeType = new UnionType([new StringType(), new ConstantBooleanType(false)]);
}
Copy link
Member

@TomasVotruba TomasVotruba Oct 8, 2025

Choose a reason for hiding this comment

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

This should be checked by version in Rector. If on PHP 8.0+, this should be skipped.
And new downgrade rule added to make it safe

Copy link
Member Author

Choose a reason for hiding this comment

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

The downgrade rule need to exists first then, as without this, the cast string will be removed at

and add back the regression bug.

After downgrade rule created, then we can safely remove this check.

Copy link
Member

Choose a reason for hiding this comment

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

Please revert this first and add PHP version check, so we don't create regressions in existing rule.
Then make a downgrade rule 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need php version check, as phpstan already check it when run on php 7.x, just need add skip config in rector.php for now:

        // on php 7.x, substr() result can return false, so force (string) is needed
        RecastingRemovalRector::class => [
            __DIR__ . '/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php',
        ],

Copy link
Member Author

Choose a reason for hiding this comment

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

}

return strtoupper('warning');
return substr('warning', 1);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of changing existing fixture, always make a new one. To make clear former one works.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

This is original fixture before the changes train, see PR order changes:

Copy link
Member

Choose a reason for hiding this comment

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

Same as before, do not change fixture, but rather add new one. Renaming a fuction that we talk about is confusing to read.

Copy link
Member

@TomasVotruba TomasVotruba Oct 8, 2025

Choose a reason for hiding this comment

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

@samsonasik Exactly my point. Instead of renaming fixture content back and forth and having to read 3 PRs to understand, they should be always related only to current PR. These PRs should be independent on each other, standalone units.

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