Skip to content

Nether Notation Coding Standard for PHP_CodeSniffer

Babs Magic edited this page May 8, 2020 · 2 revisions

Automated Formatting

This repository contains a phpcs standard for testing and automated reformatting of source to fit the standard. While most are most are, there are still some rules covered by this standard that have not yet been implemented for phpcs.

Install the Standards into your Project.

$ composer require netherphp/standards

Test code against the Standards.

Composer will have set up a little bin script. It accepts any argument that can normally be passed to phpcs. It will display a report of all the violations in all the files that it found. No changes will be made to the code at this stage.

$ nethercs <dir-or-file>

This is the same as invoking phpcs like this:

$ phpcs <dir-or-file> --standard=vendor/netherphp/standards/NetherCS

Note: if ./vendor/bin is not in your PATH you will need to use the full path to the bin scripts, vendor/bin/nethercs or vendor/bin/phpcs.

Automatically fix code to fit the Standards.

Composer will set up another bin script, nethercbf, to wrap phpcbf for you. By default nethercbf will NOT overwrite code, but create new files ending in .nethercs for you to inspect.

$ nethercbf <dir-or-file>

This is the same as invoking phpcbf like this:

$ phpcbf <dir-or-file> --standard=vendor/netherphp/standards/NetherCS --suffix=.nethercs

If you are satisfied with the results you can apply the fixes to the original code files with the following:

$ nethercbf <dir-or-file> --overwrite

Which is the same as invoking phpcbf like this:

$ phpcbf <dir-or-file> --standard=vendor/netherphp/standards/NetherCS

PHP_CodeSniffer Standards Composer Installer

If you install dealerdirect/phpcodesniffer-composer-installer after installing netherphp/standards then NetherCS will be detected as an installed standard by phpcs. This seems like an important step to get the phpcs autoloader to work as expected if you are trying to use a custom linter in your IDE to work rather than the command line interface provided by this package.

$ phpcs -i
The installed coding standards are PSR12, PSR2, Zend, PEAR, MySource, Squiz, PSR1 and NetherCS