Yesterday, I started a short series of posts covering tools that I think make for writing high-quality code in a WordPress project (specifically those that are plugins built using an object-oriented approach).

If you haven’t read the post, the first set of tools mentioned are as follows:

There are about five more tools that I like to keep running on my projects. So here’s the next three with the final two coming in the next post.

Libraries for WordPress Plugins, Continued

As previously mentioned, I find these tools useful whenever I’m working on object-oriented WordPress plugins. Furthermore, these are naturally spread across a few posts to keep each one short and focused.

PHP CodeSniffer

If you’ve been reading this blog for any length of time, you’ve likely read a post or at least mention something about PHP CodeSniffer. This is something that I think, if nothing else, every WordPress developer should have installed in their IDE.

Libraries for WordPress Plugins: PHP Coding Standards

From the project’s repository page:

PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.

Now, regarding rules, that’s a different thing. Some people prefer the WordPress Coding Standards; some prefer PSR2, some prefer other sets of rules. It’s not so much about what you prefer so long as you or your team are consistent.

And that’s what this particular library helps you do. Plus, it doesn’t hurt, that you can integrate into your IDE (assuming it’s one of the more popular editors).

PHPCPD

PHPCPD is a simple library that analyzes your code to detect duplicate code – which usually comes from being copy and pasted from somewhere else (even if it’s your code base). The idea behind the library is to reduce duplicate code.

Libraries for WordPress Plugins: PHPCPD

And it doesn’t get much clearer than this:

phpcpd is a Copy/Paste Detector (CPD) for PHP code.

In other words, it’s one step to helping you keep it DRY.

PHPMND

If one of the goals we strive for in our code is to make it as readable as possible by others who may pick up the code base, fork it, or contribute to it (especially in open source), then we need to make sure all of our values have meaningful values.

Libraries for WordPress Plugins: PHPMND

Using numbers that are meaningful to us but don’t describe what it is the code is doing is important, but it’s not something that we do, right? Or maybe that’s just me.

But that’s where PHPMND comes into play.

phpmnd is a tool that helps you detect magic numbers in PHP code. By default 0 and 1 are not considered to be magic numbers.

It’s a simple library but used in conjunction with the libraries in this post, and the previous post can help to continually increase the quality of code you’re contributing to your repositories.

One More Set of Tools

As mentioned in the previous post, the goal to which I’m working is how to incorporate all of these into a composer.json file that you can use in your project.

Remember, too, that depending on the project, you may need to select a version of the library based on the version of PHP you’re using.

Since I no longer offer comments on this site (and there are reasons for this more of which I’ll discuss again soon), feel free to tweet me about some of your preferred libraries and why you like them. If nothing else, I’m always on the lookout for more.

Finally, I’ve got one more post to publish before wrapping up this series. If you enjoyed this post, feel free to read the first in the series, as well.