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
Related
Also see:
{DIV(class="jumbotron lead")}[https://github.com/squizlabs/PHP_CodeSniffer|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.{DIV}
For the Tiki code development it is very useful tool (which is also being run automatically on Gitlab ((Continuous Integration|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:
{CODE(colors="shell")}$ ./temp/composer.phar install --prefer-dist --working-dir="vendor_bundled"{CODE}
__This will install the development packages from Composer.__
!! Usage
For example, to check a file in -+lib/+-:
{CODE(colors="shell")}$ php vendor_bundled/vendor/squizlabs/php_codesniffer/bin/phpcs lib/ocrlib.php{CODE}
To fix a file auto-magically:
{CODE(colors="shell")}$ php vendor_bundled/vendor/squizlabs/php_codesniffer/bin/phpcbf lib/ocrlib.php{CODE}
!! Fixing other errors
Some of the tiki co<x>debase hasn't been migrated to the new coding standards. If you hit a case where you would have to edit the
[https://gitlab.com/tikiwiki/tiki/-/blob/master/doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json|doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json], don't! Instead, regenerate that file with
{CODE(colors="shell")}
php doc/devtools/codesniffer/standards/TikiIgnore/generate_ignore_list.php
{CODE}
!! Related
* ((Continuous Integration))
* ((DevTips|#PHP_coding_habits|Tiki DevTips: PHP Coding Habits))
* ((PhpStorm))
Also see:
* https://github.com/squizlabs/PHP_CodeSniffer
* Example of errors reported on Gitlab CI pipeline job: https://gitlab.com/tikiwiki/tiki/-/jobs/498451366
~tc~ (alias(phpcs))~/tc~