phpMyAdmin Coding Standard
phpMyAdmin Coding Standard for PHP CodeSniffer.
Installation & Usage
Before starting using our coding standard install PHP_CodeSniffer.
Clone or download this repo somewhere on your computer or install it with Composer.
To do so, add the dependency to your
composer.json file by running
composer require --dev phpmyadmin/coding-standard.
Automatic installation with Composer
Much easier, however, is to use Composer to install the necessary files automatically.
Using the development version of phpMyAdmin from git requires using Composer, so the dependencies are already set
composer.json using the 'require-dev' section. Depending on your system, this will either be installed
automatically unless you use
--no-dev option or composer must be run with
--dev. Regardless of your composer
--dev will always install the 'require-dev' dependencies, so we recomment using Composer with that
Add the standards directory to PHP_CodeSniffer installed paths. You probably have to use the full/absolute path rather than a relative one, otherwise you will get an "Unexpected Value Exception":
$ phpcs --config-set installed_paths /var/www/html/phpmyadmin/vendor/phpmyadmin/coding-standard
You can verify whether the standard can be found:
$ phpcs -i The installed coding standards are MySource, PSR1, PHPCS, Zend, Squiz, PEAR, PSR2 and PhpMyAdmin
$ phpcs --standard=PhpMyAdmin /path/to/code
You can optionally make PhpMyAdmin the default for all invocations of phpcs, then you don't need to manually specify it each time on the command line:
$ phpcs --config-set default_standard PhpMyAdmin
PhpMyAdmin has its tuned coding style checks, such as missing
@link or other tags. Let's take a look at an example, checked with PhpMyAdmin:
$ phpcs --standard=PhpMyAdmin /path/to/code/myfile.php 123 | WARNING | Line exceeds 85 characters; contains 139 characters 184 | ERROR | Line indented incorrectly; expected at least 20 spaces, found | | 16 272 | ERROR | Closing parenthesis of a multi-line IF statement must be on a | | new line 272 | ERROR | Multi-line IF statement not indented correctly; expected 12 | | spaces but found 9