As we all know by now, applications evolve a lot during their lifetime and so does the team that works on those applications. There are always people that leave a team to transition to another team or leave the company as there are also new joiners to a team.
It’s a continuous struggle to keep up with the same approach, paradigms, or coding styles in any programming language and application with so many changes in the team or application itself.
Thankfully we have the so-called, coding standard tools, at our disposal as developers to help us mitigate these issues and make sure that everyone is on the same page and adheres to the defined rules when writing new code to extend the application and reading old code when something has to be changed.
For PHP, these tools are:
- PHP Mess Detector (PHPMD)
- PHP Code Sniffer (PHPCS)
- PHP Code Sniffer Fixer (PHPCBF)
- PHPSTAN
- PSALM
1. PHP Mess Detector (PHPMD)
PHPMD makes sure that your code follows the SOLID principles, adheres to the software design patterns, follows the naming conventions, and checks for unused code. This is all done by the list of rules the PHPMD has and those rules are grouped into 6 rulesets:
You can find out more about each of these groups and the rules that they have by visiting their respective documentation. Below you’ll find my most used configuration for this tool with 2 examples of how to override rules, specifically for naming to ignore the $id
property of a class or database model or i
,j
loop variables and how to ignore a static call for a class if there is no other way how to call that class.