Loading...
 
Skip to main content

PHP Code Sniffer

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.


For the Tiki code development it is very useful tool (which is also being run automatically on Gitlab CI for each push or merge request) to check if your code meets the Tiki PHP coding standards.

Installation

Note: This is normally handled for you by running php console.php dev:configure

In your Tiki root run the following command:

Copy to clipboard
$ ./temp/composer.phar install --prefer-dist --working-dir="vendor_bundled"

This will install the development packages from Composer.

Usage

For example, to check a file in lib/:

Copy to clipboard
$ php vendor_bundled/vendor/squizlabs/php_codesniffer/bin/phpcs lib/ocrlib.php


To fix a file auto-magically:

Copy to clipboard
$ php vendor_bundled/vendor/squizlabs/php_codesniffer/bin/phpcbf lib/ocrlib.php

Fixing other errors

Some of the tiki codebase hasn't been migrated to the new coding standards. If you hit a case where you would have to edit the
doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json, don't! Instead, regenerate that file with

Copy to clipboard
php doc/devtools/codesniffer/standards/TikiIgnore/generate_ignore_list.php



Also see:

Show PHP error messages