---
title: "PHP Festi Coding Standard"
url: https://festi.dev/8.0/Packages/CodingStandard/
---

# PHP Festi Coding Standard

The shared quality toolchain for Festi PHP projects, installed as one
Composer dev dependency: **`festi-team/coding-standard`**.

| What you get | Tool | Looks at |
|---|---|---|
| The `Festi` coding standard | PHP_CodeSniffer | style, naming, docblocks, complexity of one function |
| Class-design limits | PHPMD | size and coupling of a class, parameter counts |
| A Phan baseline and Festi plugins | Phan | types, plane separation, SQL injection, disabled guards |
| `festi-quality` | all of the above, plus the SonarQube quality gate, issues, hotspots and new uncovered lines | one summary for a project, some paths, or a change; the report of the sonar job |
| `festi-phpcs-diff` | PHP_CodeSniffer | the merge request gate: only the lines a branch changed |
| Reusable GitLab CI jobs | | the same checks in a pipeline |

The same rules run in every project's pipeline and in the
`agent_festireview` review bot, so there is one source of truth.

## Quick start

```bash
composer require --dev festi-team/coding-standard
```

Allow the Composer plugin that registers the standard with phpcs, in the
project's `composer.json`:

```json
"config": {
    "allow-plugins": {
        "dealerdirect/phpcodesniffer-composer-installer": true
    }
}
```

Then, from the project root:

```bash
vendor/bin/festi-quality                  # the whole project
vendor/bin/festi-quality src tests/Unit   # these files and directories
vendor/bin/festi-quality --diff           # only what this branch changed
vendor/bin/festi-quality --diff --list    # ... with every issue and its line
vendor/bin/festi-quality --diff --strict  # ... and fail when there is one
```

```
Festi quality summary
Scope: lines changed since origin/develop, in 3 file(s)

  phpcs  2 issues     2 errors, 0 warnings, 1 auto-fixable
  phpmd  0 issues
  phan   0 issues
  sonar  SKIPPED      set SONAR_HOST_URL and SONAR_TOKEN to read com.festi:cli

phpcs by rule
       1  Generic.Arrays.DisallowLongArraySyntax.Found
       1  Festi.NamingConventions.EntityIdNaming.VariableIdNaming
```

A Festi project is expected to have all three set up: the coding standard,
a Phan configuration and a SonarQube project.
[Installation](https://festi.dev/8.0/Packages/CodingStandard/docs/installation/index.md) covers each.

### In the sonar job

The sonar job of a project calls `festi-quality` after `sonar-scanner`:

```yaml
sonar:
  stage: test
  variables:
    GIT_DEPTH: 0
  script:
    - composer install --no-interaction --prefer-dist --no-progress
    - sonar-scanner
    - vendor/bin/festi-quality --only=sonar
```

It waits until the server has processed the scan of the job, then prints
the quality gate with each condition, the open issues, the security
hotspots to review and the files with new uncovered lines. A red gate fails
the job. The token comes only from the `SONAR_TOKEN` CI variable, and the
command does not print it. [GitLab CI](https://festi.dev/8.0/Packages/CodingStandard/docs/ci/index.md#sonarqube) has the
details and a form with two jobs.

## Documentation

| Read | To |
|---|---|
| [Installation](https://festi.dev/8.0/Packages/CodingStandard/docs/installation/index.md) | install the package, set up Phan and SonarQube, migrate an existing project |
| [Usage](https://festi.dev/8.0/Packages/CodingStandard/docs/usage/index.md) | run the checks: the whole project, paths, or a change; options, exit codes, the tools one by one |
| [GitLab CI](https://festi.dev/8.0/Packages/CodingStandard/docs/ci/index.md) | add the shipped jobs to a pipeline |
| [Rules](https://festi.dev/8.0/Packages/CodingStandard/docs/rules/index.md) | see what each rule asks for, with examples |
| [Configuration](https://festi.dev/8.0/Packages/CodingStandard/docs/configuration/index.md) | change a limit, switch a rule off, tune a Phan plugin, adopt a rule on a codebase with a backlog |
| [Extending](https://festi.dev/8.0/Packages/CodingStandard/docs/extending/index.md) | add a sniff, a PHPMD rule, a Phan plugin or a tool to `festi-quality`; test and release it |

## Requirements

| | Constraint |
|---|---|
| PHP | `>=8.1` |
| `squizlabs/php_codesniffer` | `^3.13.6 \|\| ^4.0.2` |
| `phan/phan` | `^6.0` |
| `phpmd/phpmd` | `^3.0` |
| `pdepend/pdepend` | `^3.0` |
| `slevomat/coding-standard` | `^8.22` |

All of them come with the package; a project does not require them itself.
