Education Station:
How to Write Your Own Code Sniffer

By Matthew Setter

Whether you’re new to PHP, or you’re more of a seasoned veteran, you’ve probably heard about PHP_CodeSniffer. The package, which has been around since September 2006, checks source code for coding standards violations. I’ll start off by showing you how to create a style which is a combination of other standards. I’ll then refactor it, so you learn how to pick and choose only the elements from those standards you need. Finally, I’ll step through the process of creating your own code sniff from scratch, one handling a specific use case.

This article was originally published in the December 2017 issue of php[architect] magazine. To read the complete article please subscribe or purchase the complete issue.

Leave a comment

Use the form below to leave a comment: