Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Coder Laravel Package

drupal/coder

View on GitHub
Deep Wiki
Context7

Coder

Automated tests

Coder is a library for automated Drupal code reviews and coding standard fixes. It defines rules for PHP_CodeSniffer

Built-in support for:

Online documentation: https://www.drupal.org/node/1419980

Note that Javascript support has been removed. To check and fix Javascript files please use ESLint and see the Drupal ESLint documentation.

Local installation in your Drupal project

For collaborating developer teams it makes sense to lock a Coder version with your other development dependencies locally. In your project where you have your composer.json file execute this:

composer require --dev drupal/coder

Then you can run Coder on your custom module code like this:

./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom

To simplify execution it is highly recommended to use a settings file, see below.

Usage

Check Drupal coding standards

./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom

Check Drupal best practices

./vendor/bin/phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom

Automatically fix coding standards

./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom

Store settings in a phpcs.xml.dist file

In order to save and commit your PHPCS settings to Git you can use a phpcs.xml.dist file in your project like this:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="example">
  <description>PHP CodeSniffer configuration for example development.</description>
  <!-- Check all files in the custom module directory and below. -->
  <file>web/modules/custom</file>
  <arg name="extensions" value="php,module,inc,install,test,profile,theme,info,txt,md,yml"/>

  <rule ref="Drupal">
    <!-- Example how you would disable a rule you are not compliant with yet:
    <exclude name="Drupal.Commenting.Deprecated"/>
    -->
  </rule>
  <rule ref="DrupalPractice"/>

  <!-- Example how you would disable an external rule you do not like:
  <rule ref="PEAR.Functions.ValidDefaultValue.NotAtEnd">
    <severity>0</severity>
  </rule>
  -->
</ruleset>

Then you can invoke phpcs without any options and it will read phpcs.xml.dist from the current directory. This can also be useful for Continuous Integration setups. Example:

./vendor/bin/phpcs -p

Working with Editors

Drupal Code Sniffer can be used with various editors.

Editors:

Automated Testing (PHPUnit + PHPCS + PHPStan)

Coder Sniffer comes with a PHPUnit test suite to make sure the sniffs work correctly. Use Composer to install the dependencies:

composer install

Then execute the tests:

./vendor/bin/phpunit

Then execute the coding standards checker on Coder itself:

./vendor/bin/phpcs

Then execute static analysis:

./vendor/bin/phpstan

Contributing

Please create an issue fork and merge request on drupal.org.

Thank you!

Maintainers

Credits

Juliette Reinders Folmer and Greg Sherwood, many sniffs are modified copies of their original work on PHPCS.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log