ISAAC PHP_CodeSniffer Baseliner: A Code Quality Firestarter

  • Jeroen - Senior Software Developer
    Jeroen Noten
    Senior Software Developer

Introducing a quality tool like PHP_CodeSniffer in an existing code base is hard. Only keeping new files tidy and clean rarely seems an option. But painstakingly fixing all violations in the entire codebase is cumbersome and let alone risk free. Not to speak of possible breaking changes you are introducing by running an auto fix. But not anymore, with the ISAAC PHP_CodeSniffer baseliner you are good to go in a couple of minutes. 

So what have we done? We developed a tool that automatically inserts ignore-instructions for the PHP_CodeSniffer into a project’s codebase for all violations reported by phpcsThe baseliner tool is independent of the PHPCS setup you choose, but we recommend to use the ISAAC PHP_CodeSniffer Standard, which we open sourced last year and is regularly updated. You can install the baseliner as any other composer package

Now the baseliner can do its work. Firstyou could run the PHP CodeSniffer Beautifier (phpcbf) for some specific sniffs that are safe to fix automaticallyi.e. fixes that will never introduce a breaking change, like whitespace violation fixes. Then, you leverage the baseliner tool to fully automatically insert // phpcs:ignore instructions for each coding standard violation. This way you can easily oversee any violations that still have to be fixed manually and add phpcs to CI pipelines and/or git hooks without having to touch existing code. 

GitHub links: PHP_CodeSniffer Baseliner and PHP_CodeSniffer Standard