Contributing to Coder

Last updated on
29 November 2023

Coder is not perfect (yet) and you can contribute towards making it better. There are two parts to the coder_sniffer system - a part that catches violations in coding standards in your code and a part that automatically fixes those violations that are automatically fixable. The rule set that is included in the former is very comprehensive but is not completely exhaustive and there could be gaps in how violations are caught. Not all violations that can be automatically fixed have logic implemented for the automatic fixes.

You can contribute towards the development of coder module in two ways

a) By helping improve the rules - By using coder, checking how the rules apply to your code and checking the reported errors against coding standards and against your code and confirming that the rules are indeed catching the errors and only the errors.

b) By helping improve the automatic fixes - Coder users PHP Code Sniffer which comes with a good tokenizer and a good set of documented functions. PHP Code Sniffer (phpcs) comes with the PHP Code Beautifier and Fixer (phpcbf) which is used for automatically fixing such errors that can be automatically fixed.

Installing Coder

You will have to install the latest PHP Code Sniffer using the instructions provided (Remember to install it from the source / git repository to keep pulling the latest version)

Creating fixes and pull requests

  1. Make sure an issue exists at https://www.drupal.org/project/issues/coder
  2. Create a Pull Request against https://github.com/pfrenssen/coder
  3. Post a link to the pull request to the issue on drupal.org and set the issue to "needs review"

Creating tests and testing your fixes

Once you fix a bug or create an automatic fix you will have to create corresponding tests within the Coder system. Each negative test case (a piece of code that should result in an error) should be added to the corresponding Unit Test file for the specific sniff. Each positive test case should be added to the good.php at Tests/good/good.php.

You should run ./vendor/bin/phpunit once you apply your fix to confirm that the tests pass.

Coding standards inside Coder

Coder itself uses the PHPCS coding standard and any changes you make to the system should be tested using phpcs standard=PHPCS

Help improve this page

Page status: No known problems

You can: