Migration of route methods from Slim 2 to Slim 4 #6668
Replies: 1 comment 1 reply
-
Hi, thanks for question with real PHP examples. I think this is a great use case to save yourself big amount of manual work 👍 Rector tried to follow unix philosophy - build simple rules that handle 1 job right, then connect them together solid realible machine. From top of my head, I see there 3 different rules:
Of course you can fit those to one big God Rector that handles everything and have just 1 file :) but in my experience, this crashes programmers brains with cognitive overload, as they juggle too many concepts at once and get confused with ever simple operation like variable rename. It's better to just modify the node, instead of replacing it. $node = new Node\Stmt\ClassMethod(new Identifier('newName')); vs. $node->name = new Identifier('newName'); Why? Each node hold so called "attributes", that contain metadata about spaces, parent nodes, resolved names and types. These metadata are important to static type resolving and printing node in code in original format as much as possible. Creating a new node will remove all these attributes and can break stuff. It's also best practise to change as small node as possible. E.g. if you need to rename 1 method, you should not do it on
Last thing... if it works, it's good enough :) if this rule is create & apply & remove, there is no need to write it with best practises in mind. Just run it, refactor and throw it away :). But if you plan to help you the Slim community and release this is a migration set, best practise will make these rule more reliable and easy to fix. I think you're on the right path. Good luck 👍 |
Beta Was this translation helpful? Give feedback.
-
We want to migrate our route methods (essentially from Slim 2 to Slim 4). We thought we should try it with rector for the first time ;-)
The main aspects are:
Previous code:
Target code:
Our rector by now (which sets the method arguments and the return type):
Now our questions:
Beta Was this translation helpful? Give feedback.
All reactions