[composer-based] Add Twig composer-based set - #996
Merged
Conversation
Adds config/sets/twig/composer-based.php, mirroring the Symfony one: rules and rule configuration bound to the twig/twig version installed in the analysed project, so a direct upgrade from any older Twig version is covered by a single set. The existing per-version Twig sets are left untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
config/sets/twig/composer-based.php, the Twig counterpart ofconfig/sets/symfony/composer-based.php. Rules and rule configuration are bound to thetwig/twigversion installed in the analysed project, so a direct upgrade from any older Twig version is covered by a single set, instead of chainingtwig112→twig127→ … →twig30.The existing per-version Twig sets are left untouched.
What the set does
final class SomeTwigUse { - public function run(Twig_Environment $twigEnvironment) + public function run(\Twig\Environment $twigEnvironment) { - return new Twig_SimpleFilter('some_filter', 'strlen'); + return new \Twig\TwigFilter('some_filter', 'strlen'); } }Version bonds
>=1.12 <1.40Twig_Function/Twig_Filter/Twig_Test→Twig_Simple*renames>=1.27Twig_Node/Twig_Template/Twig_Errormethod renames>=1.34SimpleFunctionAndFilterRector>=1.40>=3.0getFilters()/getFunctions()/getTests()arrayreturn typesTwo spots where the flat set cannot be a literal copy of the version sets, as all rules now run at once:
1.12renames are capped at<1.40— from 1.40 on, the namespaced rename maps the very same classes directly toTwig\TwigFunctionetc., so keeping both would makeRenameClassRectorping-pong betweenTwig_FunctionandTwig_SimpleFunctionTwig_SimpleFilter→Twig_Filter) is not repeated; both underscore names already lead to the same namespaced class in the>=1.40groupTwig_Function_Nodehad no namespaced target in the version sets (it went throughTwig_SimpleFunction), so the>=1.40group maps it toTwig\TwigFunctiondirectly, to keep the same end stateTwig_Tests_EnvironmentTest_Extension→Twig\Tests\EnvironmentTest\Extensiomapping was left out, as the target class name is truncatedRule bonding
SimpleFunctionAndFilterRectornow implementsComposerPackageConstraintInterface(twig/twig >=1.34), same as the other bonded rules. Its test reads the version from a standalonecomposer.json.twig/twigis added torequire-dev, so the composer-bound configuration is active in tests — without it the whole set is skipped and untestable.