Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

DDEV PHP Code Quality

Adds phpcs, phpcbf and phpstan commands to wrap web container commands.

Installation

ddev add-on get useraccesshub/ddev-php-code-quality
ddev restart

Post Installation Configuration

This add-on does not include any specific standards so these will need to be included manually.

Drupal 11

  1. Add the drupal/core-dev package or individual phpcs/phpstan packages:
ddev composer require --dev drupal/core-dev

OR

ddev composer require --dev drupal/coder
ddev composer require --dev phpstan/phpstan phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules
  1. 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>
  1. Add a phpstan.neon file at the project root:
parameters:
  level: 5
  excludePaths:
    - *node_modules/*
    - *vendor/*
    - *.twig
  fileExtensions:
    - php
    - module
    - inc
    - install
    - test
    - profile
    - theme

Usage

Run commands

ddev phpcs path/to/file/or/directory
ddev phpcbf path/to/file/or/directory
ddev phpstan analyze path/to/file/or/directory

Show configuration options:

ddev phpcs --config-show

Get installed code standards:

ddev phpcs -i

About

DDEV Add-On to add phpcs, phpcbf and phpstan commands to composer based projects.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors