Posts

Showing posts with the label refactoring

Next generation refactoring with syntactical grep and patch from pfff

Image
Refactoring of PHP methods is often difficult: syntax errors or non-existing methods are only detected during runtime wrong method calls or uninitialized variables are only detected during runtime wrong order of parameters often remains undetected not enough unit tests to validate the changes not many resources for refactoring (time + money) We can solve most of these issues by using a few tools for syntactic analysis. You might have already worked with grep to search your code: # find a function in all PHP files (and sub-directories) grep -rin "SomeFunc(" *.php This also finds "doSomeFunc(" as well as strings or documentation containing "SomeFunc(". If you want to find all occurrences of SomeFunc() with exactly 2 parameters or at least 1 parameter, things get complicated. Happily, Facebook has released a few tools to run static analysis and source-to-source transformations on PHP code. The package is named pfff and is available on GitHub . Synta...