In my last article on torque, I wrote why I think PHP code that follows the coding standards set by the PHP community is more meaningful than that set for the core of word press. These standards are based on existing requirements based on old code and are limited to language functions over 10 years. When launching a new WordPress plug-in, website or application, the situation is completely different, but there is no reason to make the same decision. As a follow-up to this article, I want to show you how to technically implement and comply with established standards, such as psr-2 or WordPress coding standards. You can do this using a tool called PHP code sniffer. This article will show you how to use this and other tools to test code for compliance with these rules and automatically modify most deviations. Also print the code. The
Why is coding standard important? In general, this is important when people write to coding standards because it makes the code easier to read and reduces the need for multiple developers in the project. This is all true. I agree. But that’s not why I like applying code styles and automatically modifying them in my code. If you don’t worry about the code style, I think you can think less about binding text on the screen and focus more on the actual code. It’s not easy to write code. It helps to pay more attention. It’s really important to think less about things you don’t need to think about For example, you can consider how the object representation of an HTTP request is designed. There are many completely effective ways to solve the problem. But, like others, follow the mode set by the psr-7 standard. When you choose a framework to run code instead of just following standard standards, the effect will be very good when the framework selection has no impact on the code you are writing. The
I am not saying that I have rewritten WordPress and built it to interoperate with the PHP framework. The WordPress rest API and wp-cli can help you check for these problems. Instead, we are talking about custom site code or plug-ins. Sniffer PHP code sniffer finds smelly code. The term \
Using code sniffer, you can \
The following is a command to add code listening to a project using Composer: Note that the composer used the squizlabs\/php_codesniffer dev required dev flag. This is added to the \
Add a script named sniffs. For each directory to be scanned, you want to execute the \
The{
Script:{
\
}The
}Now, whenever you run the is script, if you use – \
Enforcing the criteria for sorting code on a solution page is not a big time investment. Instead, set the IDE to follow standards and use the PHP encoding standard filer to automatically modify most of the deviations. You can go to the code style section of the setup from phpstorm. In PHP settings, the option named \
Male compsoer requires friendofphp \/ PHP CS fixer dev. This beautiful gadget solves most of the code problems. If I can’t do that, I will explain the problem in an easy to correct way. Let’s add another script for lint to the composer file. The{
Script:{
\
\
}The
}Put all the code for each task in one script. A script will be added later to call another script in the correct order. The
Lintersnifer looks for code that may be maintaining long-term problems, and linter looks for errors. It is important to remember that neither runs code. They all analyze text files with code. Printing does not replace testing. However, I like to run one between modifying the program and testing. So if I miss something bad, or the fix is wrong, I will not run the test, but will be marked. Anyway, I will fail. There are several PHP prints. Parallel lint likes to process multiple files at once and then one file at a time because it is faster. The name illustrates this. A wonderful performance. Let’s install the following: The
Composers need Jakub onderka \/ PHP parallel lint. The linter command is \
Script:{
\
\
\
}The
}All of them are pulled together. Now, with these three scripts, you can run all of them with only one command phpun