Adds phpcs, phpcbf and phpstan commands to wrap web container commands.
ddev add-on get useraccesshub/ddev-php-code-quality
ddev restartThis add-on does not include any specific standards so these will need to be included manually.
- Add the drupal/core-dev package or individual phpcs/phpstan packages:
ddev composer require --dev drupal/core-devOR
ddev composer require --dev drupal/coder
ddev composer require --dev phpstan/phpstan phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules- Add a phpcs.xml file at the project root:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Drupal Project">
<description>Default PHP CodeSniffer configuration for Drupal.</description>
<!-- Check these file extensions -->
<arg name="extensions" value="php,module,inc,install,test,profile,theme"/>
<!-- Use colors in output and show sniff names -->
<arg name="colors"/>
<arg value="s"/>
<!-- Core Drupal standards from the Coder module -->
<rule ref="Drupal"/>
<rule ref="DrupalPractice"/>
<!-- Files or directories to check -->
<file>web/modules/custom</file>
<file>web/themes/custom</file>
<!-- Directories to ignore -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/dist/*</exclude-pattern>
</ruleset>
- Add a phpstan.neon file at the project root:
parameters:
level: 5
excludePaths:
- *node_modules/*
- *vendor/*
- *.twig
fileExtensions:
- php
- module
- inc
- install
- test
- profile
- themeRun commands
ddev phpcs path/to/file/or/directory
ddev phpcbf path/to/file/or/directory
ddev phpstan analyze path/to/file/or/directoryShow configuration options:
ddev phpcs --config-showGet installed code standards:
ddev phpcs -i