PHPackages                             brianvarskonst/coding-standard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. brianvarskonst/coding-standard

ActivePhpcodesniffer-standard[Testing &amp; Quality](/categories/testing)

brianvarskonst/coding-standard
==============================

Coding Standard Rules for CodeSniffer for writing consistent PHP code

017PHP

Since Jun 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/brianvarskonst/coding-standard)[ Packagist](https://packagist.org/packages/brianvarskonst/coding-standard)[ RSS](/packages/brianvarskonst-coding-standard/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Brianvarskonst Coding Standard
==============================

[](#brianvarskonst-coding-standard)

Provides a PHP CodeSniffer ruleset for the Brianvarskonst coding standard

[![Build Status](https://github.com/brianvarskonst/coding-standard/actions/workflows/ci.yml/badge.svg)](https://github.com/brianvarskonst/coding-standard/actions)

[![Latest Stable Version](https://camo.githubusercontent.com/2e1e96c27bf7438d4e73c21f4f3a97a38096824b24bc41f4c5f2abf1e6b333ac/687474703a2f2f706f7365722e707567782e6f72672f627269616e766172736b6f6e73742f636f64696e672d7374616e646172642f76)](https://packagist.org/packages/brianvarskonst/coding-standard)[![Total Downloads](https://camo.githubusercontent.com/d848760576f097522103d9ded93cfbae9d3d80bcbadf87b1e404c026d5ab6941/68747470733a2f2f706f7365722e707567782e6f72672f627269616e766172736b6f6e73742f636f64696e672d7374616e646172642f646f776e6c6f616473)](https://packagist.org/packages/brianvarskonst/coding-standard)[![Latest Unstable Version](https://camo.githubusercontent.com/794a02e56c72f5102ccfd6396745b11aac9f12e49107dafe7bc28bcb6b07a48e/687474703a2f2f706f7365722e707567782e6f72672f627269616e766172736b6f6e73742f636f64696e672d7374616e646172642f762f756e737461626c65)](https://packagist.org/packages/brianvarskonst/coding-standard)[![Version](https://camo.githubusercontent.com/8b8225b569dde4179724bd4b29b9c87a4a3f7df4f2e926f23d09164891a74916/687474703a2f2f706f7365722e707567782e6f72672f627269616e766172736b6f6e73742f636f64696e672d7374616e646172642f76657273696f6e)](https://packagist.org/packages/brianvarskonst/coding-standard)

[![PHPStan](https://camo.githubusercontent.com/43cbcc4193ce0d13c99fbc045f1f6bdd0de0d7f00a1429e751727038a25769f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374796c652d6c6576656c253230382d627269676874677265656e2e7376673f266c6162656c3d7068707374616e)](https://camo.githubusercontent.com/43cbcc4193ce0d13c99fbc045f1f6bdd0de0d7f00a1429e751727038a25769f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374796c652d6c6576656c253230382d627269676874677265656e2e7376673f266c6162656c3d7068707374616e)[![composer.lock](https://camo.githubusercontent.com/c8bb4029caf433b1f078947a78a1326af1c0881c8caa6cb35845cb08916290b4/687474703a2f2f706f7365722e707567782e6f72672f627269616e766172736b6f6e73742f636f64696e672d7374616e646172642f636f6d706f7365726c6f636b)](https://packagist.org/packages/brianvarskonst/coding-standard)[![License](https://camo.githubusercontent.com/e5b5503a000a305808680366af6463a6195b582a1f068486955deb9262ee0fce/687474703a2f2f706f7365722e707567782e6f72672f627269616e766172736b6f6e73742f636f64696e672d7374616e646172642f6c6963656e7365)](https://packagist.org/packages/brianvarskonst/coding-standard)

Overview
--------

[](#overview)

The Brianvarskonst Coding Standard is an extension of the [Symfony Coding Standard](http://symfony.com/doc/current/contributing/code/standards.html) and adds specific rules for ensuring code quality and consistency.

> PHP 8.0+ coding standard

Rules
-----

[](#rules)

### Brianvarskonst.Array.ArrayDoubleArrowAlignment

[](#brianvarskonstarrayarraydoublearrowalignment)

- `=>` operators must be aligned in associative arrays.
- Keys and `=>` operators must be on the same line in arrays.

### Brianvarskonst.Array.MultiLineArray

[](#brianvarskonstarraymultilinearray)

- Opening brackets must be followed by a newline in multi-line arrays.
- Closing brackets must be on their own line.
- Elements must be indented in multi-line arrays.

### Brianvarskonst.Formatting.AlphabeticalUseStatements

[](#brianvarskonstformattingalphabeticalusestatements)

- `use` statements must be sorted lexicographically.
- Configurable sorting order via `order` property.

#### Configuration

[](#configuration)

The `order` property of the `Brianvarskonst.Formatting.AlphabeticalUseStatements` sniff defines which function is used for ordering.

Possible values for order:

- `dictionary` (default): based on [strcmp](http://php.net/strcmp), the namespace separator precedes any other character ```
    use Doctrine\ORM\Query;
    use Doctrine\ORM\Query\Expr;
    use Doctrine\ORM\QueryBuilder;
    ```
- `string`: binary safe string comparison using [strcmp](http://php.net/strcmp)```
    use Doctrine\ORM\Query;
    use Doctrine\ORM\QueryBuilder;
    use Doctrine\ORM\Query\Expr;

    use ExampleSub;
    use Examples;
    ```
- `string-locale`: locale based string comparison using [strcoll](http://php.net/strcoll)
- `string-case-insensitive`: binary safe case-insensitive string comparison [strcasecmp](http://php.net/strcasecmp)```
    use Examples;
    use ExampleSub;
    ```

To change the sorting order for your project, add this snippet to your custom `ruleset.xml`:

```

```

### Brianvarskonst.Formatting.UnnecessaryNamespaceUsageSniff

[](#brianvarskonstformattingunnecessarynamespaceusagesniff)

- The imported class name must be used, when it was imported with a `use` statement.

### Brianvarskonst.String.VariableInDoubleQuotes

[](#brianvarskonststringvariableindoublequotes)

- Interpolated variables in double-quoted strings must be surrounded by `{}`, e.g., `{$VAR}`. instead of `$VAR`.

### Brianvarskonst.WhiteSpace.ConstantSpacing

[](#brianvarskonstwhitespaceconstantspacing)

- `const` must be followed by a single space.

### Brianvarskonst.WhiteSpace.MultipleEmptyLines

[](#brianvarskonstwhitespacemultipleemptylines)

Source: [mediawiki/mediawiki-codesniffer](https://github.com/wikimedia/mediawiki-tools-codesniffer)

- No more than one empty consecutive line is allowed.

### Brianvarskonst.Usage.ElementNameMinimalLength

[](#brianvarskonstusageelementnameminimallength)

- Functions, classes, interfaces, traits, and constants must use names with a minimum length (default 3 characters).
- Configurable via `minLength` and `allowedShortNames`.

```

```

alternatively, whitelist can be extended via `additionalAllowedNames` config, e.g.:

```

```

### Brianvarskonst.Complexity.NestingLevel

[](#brianvarskonstcomplexitynestinglevel)

- Ensures a maximum nesting level within functions/methods.
- Default triggers a warning at level 3 and an error at level 5.
- Configurable via `warningLimit` and `errorLimit`.

For example:

```
function foo(bool $level_one, array $level_two, bool $level_three)
{
    if ($level_one) {
        foreach ($level_two as $value) {
            if ($level_three) {
                return $value;
            }
        }
    }

    return '';
}
```

The example codes contains a nesting level of 3.

By default, the sniff triggers a *warning* if nesting is equal or bigger than 3, and triggers an *error* if nesting is equal or bigger than 5.

The warning and error limit can be customized via, respectively, `warningLimit` and `errorLimit`properties:

```

```

There's an exception. Normally a `try`/`catch`/`finally` blocks accounts for a nesting level, but this sniff ignores the increase of level causes by a `try`/`catch`/`finally` that is found immediately inside the level of function.

For example, the following code would be fine:

```
function bar(array $data, string $foo): string
{
    // Indent level 1
    try {
        $encoded = json_encode($data, JSON_THROW_ON_ERROR);
        // Indent level 2
        if ($encoded) {
            // Indent level 3
            if ($append !== '') {
                return $encoded . $foo;
            }

            return $encoded;
        }

        return '';
    } catch (\Throwable $e) {
        return '';
    }
}
```

In fact, the two nested `if`s would account for an indent level of 2, plus the `try`/`catch`block that would be 3, but because the `try`/`catch` is directly inside the function it is ignored, so the max level considered by the sniff is 2, which is inside the limit.

This exception in the regard of `try`/`catch`/`finally` blocks can be disabled via the `ignoreTopLevelTryBlock` property:

```

```

### Brianvarskonst.Classes.PropertyPerClassLimit

[](#brianvarskonstclassespropertyperclasslimit)

- Ensures a maximum number of properties per class (default 10).
- Configurable via `maxCount`.

```

```

### Brianvarskonst.Namespace.Psr4

[](#brianvarskonstnamespacepsr4)

- Enforces PSR-4 autoload standards.
- Configurable to match `composer.json` autoload settings.

Our style enforce the use of PSR-4 for autoload. This sniff make use of some configuration to check that files that contain classes are saved using the structure expected by PSR-4. If there is no configuration provided the sniff only checks that class name and match file name, which is not a warranty of PSR-4.

The needed configuration is specular to the PSR-4 configuration in `composer.json` like:

```
{
  "autoload": {
    "psr-4": {
      "Brianvarskonst\\Foo\\": "src/"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "Brianvarskonst\\Foo\\Tests\\": "tests/php/"
    }
  }
}
```

The rule configuration should be:

```

```

Please note that when a PSR-4 configuration is given, *all* autoloadable entities (classes/interfaces/trait) are checked to be compliant. If there are entities in the sniffer target paths that are not PSR-4 compliant (e.g. loaded via classmap or not autoloaded at all) those should be excluded via `exclude` property, e.g.:

```

```

Note that anything that *starts with* any of the values in the `exclude` array will be excluded.

E.g. by excluding `Brianvarskonst\ExcludeThis` things like `Brianvarskonst\ExcludeThis\Foo` and `Brianvarskonst\ExcludeThis\Bar\Baz` will be excluded as well.

To make sure what's excluded is a namespace, and not a class with same name, just use `\` as last character.

### Included rules

[](#included-rules)

Further rules are imported from other standards, detailed in [`ruleset.xml`](Brianvarskonst/ruleset.xml).

Most of the issues can be auto-fixed with `phpcbf`.

#### PSR-1, PSR-2, PSR-12

[](#psr-1-psr-2-psr-12)

For more information about included rules from PHP Standards Recommendations (PSR), refer to the official documentation:

- [PSR-1](https://www.php-fig.org/psr/psr-1)
- [PSR-2](https://www.php-fig.org/psr/psr-2)
- [PSR-12](https://www.php-fig.org/psr/psr-12)

#### Slevomat

[](#slevomat)

A few rules have been included from the [Slevomat Coding Standard](https://github.com/slevomat/coding-standard).

#### Symfony

[](#symfony)

A few rules have been included from the [Symfony Coding Standard](https://github.com/djoos/Symfony-coding-standard).

#### Generic Rules

[](#generic-rules)

Some rules are also included from PHP\_CodeSniffer itself, as well as [PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra).

Requirements
------------

[](#requirements)

- [PHP](http://php.net)
- [Composer](https://getcomposer.org/)

Installation
------------

[](#installation)

### Composer

[](#composer)

Using [Composer](https://getcomposer.org/) is the preferred way.

1. Add the Brianvarskonst coding standard to `composer.json`

```
$ composer require --dev brianvarskonst/coding-standard
```

2. Use the coding standard:

```
$ ./vendor/bin/phpcs --standard=Brianvarskonst path/to/my/file.php
```

3. Optionally, set Brianvarskonst as the default coding standard:

```
$ ./vendor/bin/phpcs --config-set default_standard Brianvarskonst
```

### Source

[](#source)

1. Clone the repository:

```
$ git clone https://github.com/brianvarskonst/coding-standard.git
```

2. Install dependencies:

```
$ composer install

```

3. Verify coding standards:

```
$ ./vendor/bin/phpcs -i
```

4. Use the coding standard:

```
$ ./vendor/bin/phpcs --standard=Brianvarskonst path/to/my/file.php
```

5. Optionally, set Brianvarskonst as the default coding standard:

```
$ ./vendor/bin/phpcs --config-set default_standard Brianvarskonst

```

Troubleshooting
---------------

[](#troubleshooting)

If `phpcs` complains that `Brianvarskonst` coding standard is not installed, please check the installed coding standards with `phpcs -i` and that `installed_paths` is set correctly with `phpcs --config-show`

Removing or Disabling Rules
---------------------------

[](#removing-or-disabling-rules)

### Rules Tree

[](#rules-tree)

Sometimes it is necessary to not follow certain rules. To avoid error reporting, you can:

- Remove rules for an entire project via configuration.
- Disable rules from code, only in specific places.

In both cases, it is possible to remove or disable:

- A complete standard
- A standard subset
- A single sniff
- A single rule

These elements are in a hierarchical relationship: `standards` consist of one or more `subsets`, which contain one or more `sniffs`, which in turn contain one or more `rules`.

### Removing Rules via Configuration File

[](#removing-rules-via-configuration-file)

Rules can be removed for the entire project by using a custom `phpcs.xml` file, like this:

```

```

In the example above, the `PSR1.Classes.ClassDeclaration` sniff (and all the rules it contains) has been removed.

By using `PSR1` instead of `PSR1.Classes.ClassDeclaration`, you would remove the entire `PSR1` standard. Whereas using `PSR1.Classes.ClassDeclaration.MultipleClasses` would remove this one rule only, without affecting other rules in the `PSR1.Classes.ClassDeclaration` sniff.

### Removing Rules via Code Comments

[](#removing-rules-via-code-comments)

Removing a rule/sniff/subset/standard only for a specific file or part of it can be done using special `phpcs` annotations/comments. For example, `// phpcs:disable` followed by an optional name of a standard/subset/sniff/rule. Like so:

```
// phpcs:disable PSR1.Classes.ClassDeclaration
```

For more information about ignoring files, please refer to the official [PHP\_CodeSniffer Wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file).

IDE Integration
---------------

[](#ide-integration)

### PhpStorm

[](#phpstorm)

After installing the coding standard package as described above, configure PhpStorm to use PHP\_CodeSniffer by following these steps:

1. Open PhpStorm settings and navigate to:

> `Language & Frameworks` -&gt; `PHP` -&gt; `Quality Tools` -&gt; `PHP_CodeSniffer`.

2. In the `Configuration` dropdown, select `Local`.
3. Click the `...` button next to the dropdown to open a dialog for specifying the path to the PHP\_CodeSniffer executable.
4. In the file selection dialog, navigate to `vendor/bin/` in your project directory and select `phpcs`. On Windows, select `phpcs.bat`.
5. Click the `Validate` button next to the path input field. If everything is set up correctly, a success message will appear at the bottom of the window.
6. Still in the PhpStorm settings, navigate to:

> `Editor` -&gt; `Inspections`

7. In the search field, type `codesniffer` and then select:

> `PHP` -&gt; `Quality Tools` -&gt; `PHP_CodeSniffer validation`

8. Enable it by checking the corresponding checkbox and clicking `Apply`.
9. Select `PHP_CodeSniffer validation`, then click the refresh icon next to the `Coding standard` dropdown on the right and choose `Brianvarskonst`.

    - If `Brianvarskonst` is not listed, select `Custom` as the standard and use the `...` button next to the dropdown to specify the `phpcs.xml` file.

Once PhpStorm is integrated with PHP\_CodeSniffer, warnings and errors will automatically be highlighted in your IDE editor.

Dependencies
------------

[](#dependencies)

- [PHP CodeSniffer](https://github.com/phpcsstandards/PHP_CodeSniffer)
- [David Joos's Symfony Coding Standard](https://github.com/djoos/Symfony-coding-standard)
- [Composer installer for PHP\_CodeSniffer coding standards](https://github.com/DealerDirect/phpcodesniffer-composer-installer)
- [Slevomat Coding Standard](https://github.com/slevomat/coding-standard)
- [PHPCSStandards / PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils)

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for information.

License
-------

[](#license)

Copyright (c) 2024, Brianvarskonst under [MIT](LICENSE) License

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf03621c5b64669782bf2ab9aff80d90548033a70282eab415263d3d5729d3d4?d=identicon)[brianvarskonst](/maintainers/brianvarskonst)

---

Top Contributors

[![brianvarskonst](https://avatars.githubusercontent.com/u/53712359?v=4)](https://github.com/brianvarskonst "brianvarskonst (30 commits)")

---

Tags

code-stylecoding-standardphpphp8phpcodesnifferphpcodesniffer-standardphpcsphpcs-standard

### Embed Badge

![Health badge](/badges/brianvarskonst-coding-standard/health.svg)

```
[![Health](https://phpackages.com/badges/brianvarskonst-coding-standard/health.svg)](https://phpackages.com/packages/brianvarskonst-coding-standard)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M571](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
