Skip to content

[Core] Add Option::ALLOW_BC_BREAK option via --allow-bc-break #1744

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

Closed
wants to merge 8 commits into from

Conversation

samsonasik
Copy link
Member

Fixes rectorphp/rector#6872

So it can be used in the rules to be used to upgrade application, eg: on TypedPropertyRector, using:

vendor/bin/rector --allow-bc-break

to update non-private property as well.

@samsonasik samsonasik marked this pull request as draft January 30, 2022 12:51
@samsonasik
Copy link
Member Author

implemented 🎉 applied the example use case to TypedPropertyRector

@samsonasik samsonasik marked this pull request as ready for review January 30, 2022 13:29
@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba
Copy link
Member

I'm not sure about usefulness of this change, as any rule can be potentially BC break. Just 99.99 % cases isn't.

We would have to introduce huge level of complexity to maintain it to be reliable enough to be true. Otherwise it will loose trust and make it irrelevant. Same thing happened to PHP CS Fixer, where not-risky rules are breaking code and are not reliable.

İt should bee solved on rule level.

@samsonasik
Copy link
Member Author

samsonasik commented Jan 30, 2022

The BC-Break only applied when using --allow-bc-break, and it is optional, which requires change in the rules that potentially usefull for its use, eg: TypedPropertyRector, other won't.

I add its check https://github.com/rectorphp/rector-src/pull/1744/files#diff-cbdd57028cbf699819fb6adde8248728f712c6e75d0640239e089b5a1b73b8e8 before last checking for private and protected property only. Other previously skipped check verify still apply, eg: on interface, modified by trait, etc.

I think it is usefull for an application/library that requires a BC break major change, eg from version 1 to version 2.

Do you think the alternative is create a separate namespace like in original issue, eg: BcBreak namespace?

@TomasVotruba
Copy link
Member

I understand the feature. Yet which is the complete list that are enabled/disabled by this flag, that is the hard question.
E.g. AddParamTypeDeclarationRector can break BC, but that's intentional as framework upgrade should follow.

The BC breaks should be avoided unless intentional on package upgrade.

Maybe this can be resolved on already existing level without marking each of ~600 rules as BC break/non BC break.

As for the typed property example, what change in code is needed?

@samsonasik
Copy link
Member Author

samsonasik commented Jan 30, 2022

Previously, before rector 0.12.9, eg on rector 0.12.8, there are 2 options: classLikeTypeOnly = false and privatePropertyOnly = false:

private bool $classLikeTypeOnly = false;
/**
* If want to keep BC, it can be set to true
* @see https://3v4l.org/spl4P
*/
private bool $privatePropertyOnly = false;

which when user want to only update the code to update private property only, they can enable it via set in rector.php:

    $services = $containerConfigurator->services();
    $services->set(TypedPropertyRector::class)
        ->call('configure', [[
            TypedPropertyRector::PRIVATE_PROPERTY_ONLY => true,
        ]]);

Start from 0.12.9, TypedPropertyRector is no longer configurable, above settings is removed at #1496 and it only changes:

– private property
– protected property on final class without extends

which make user that want to upgrade the code for other modifiers except above is not possible.

@TomasVotruba
Copy link
Member

Closing as separate rule is a better way: #1745 (comment)

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.

Add new namespaced rules under "BcBreak" namespace
3 participants