Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tomas Votruba:
Why AST Fixes your Coding Standard Better than Tokens
Oct 30, 2018 @ 16:15:58

Tomas Votruba has a new post to his site explaining some of the reasoning behind his opinion that AST (abstract syntax tree) processing can help fix your code better than simple token detection and make its overall quality better.

In the last post Brief History of Tools Watching and Changing Your PHP Code we saw there are over dozen tools in PHP that can modify code. So there is no surprise coding standard tools are "upgrading" code from PHP 5.6 to PHP 7.2 without knowing types and that AST is moving false to !.

Should coding standard upgrade your code? Should AST make your code cleaner? Should AST take of coding standard changes? Which is born for it?

He starts with a brief look at token detection with the PHP CS fixer and its use of token_get_all to identify locations needing change. He then compares this to AST changes that include some logic such as changing if statement evaluation to be more correct and optimizing foreach statements. He goes on to talk about what token detection is good at and what AST is good for as well as providing an example for standards changes in AST.

tagged: exakat,review,v1.4.3

Link: https://www.tomasvotruba.cz/blog/2018/10/25/why-ast-fixes-your-coding-standard-better-than-tokens/


Trending Topics: