{"id":33983590,"url":"https://github.com/brianvarskonst/coding-standard","last_synced_at":"2026-05-31T02:31:20.201Z","repository":{"id":242387809,"uuid":"809419986","full_name":"brianvarskonst/coding-standard","owner":"brianvarskonst","description":"Coding Standard Rules for CodeSniffer  for writing consistent PHP code","archived":false,"fork":false,"pushed_at":"2024-06-26T12:14:04.000Z","size":221,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-14T16:40:23.900Z","etag":null,"topics":["code-style","coding-standard","php","php8","phpcodesniffer","phpcodesniffer-standard","phpcs","phpcs-standard"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brianvarskonst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-02T16:31:15.000Z","updated_at":"2024-06-26T12:14:07.000Z","dependencies_parsed_at":"2024-06-13T18:19:28.971Z","dependency_job_id":null,"html_url":"https://github.com/brianvarskonst/coding-standard","commit_stats":null,"previous_names":["brianvarskonst/coding-standard"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brianvarskonst/coding-standard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvarskonst%2Fcoding-standard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvarskonst%2Fcoding-standard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvarskonst%2Fcoding-standard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvarskonst%2Fcoding-standard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brianvarskonst","download_url":"https://codeload.github.com/brianvarskonst/coding-standard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvarskonst%2Fcoding-standard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33717415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-style","coding-standard","php","php8","phpcodesniffer","phpcodesniffer-standard","phpcs","phpcs-standard"],"created_at":"2025-12-13T04:05:11.317Z","updated_at":"2026-05-31T02:31:20.195Z","avatar_url":"https://github.com/brianvarskonst.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brianvarskonst Coding Standard\n\nProvides a PHP CodeSniffer ruleset for the Brianvarskonst coding standard\n\n[![Build Status](https://github.com/brianvarskonst/coding-standard/actions/workflows/ci.yml/badge.svg)](https://github.com/brianvarskonst/coding-standard/actions)\n\n[![Latest Stable Version](http://poser.pugx.org/brianvarskonst/coding-standard/v)](https://packagist.org/packages/brianvarskonst/coding-standard)[![Total Downloads](https://poser.pugx.org/brianvarskonst/coding-standard/downloads)](https://packagist.org/packages/brianvarskonst/coding-standard)\n[![Latest Unstable Version](http://poser.pugx.org/brianvarskonst/coding-standard/v/unstable)](https://packagist.org/packages/brianvarskonst/coding-standard)\n[![Version](http://poser.pugx.org/brianvarskonst/coding-standard/version)](https://packagist.org/packages/brianvarskonst/coding-standard)\n\n![PHPStan](https://img.shields.io/badge/style-level%208-brightgreen.svg?\u0026label=phpstan)\n[![composer.lock](http://poser.pugx.org/brianvarskonst/coding-standard/composerlock)](https://packagist.org/packages/brianvarskonst/coding-standard)\n[![License](http://poser.pugx.org/brianvarskonst/coding-standard/license)](https://packagist.org/packages/brianvarskonst/coding-standard)\n\n## Overview\n\nThe 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.\n\n\u003e PHP 8.0+ coding standard\n\n## Rules\n\n### Brianvarskonst.Array.ArrayDoubleArrowAlignment\n* `=\u003e` operators must be aligned in associative arrays.\n* Keys and `=\u003e` operators must be on the same line in arrays.\n\n### Brianvarskonst.Array.MultiLineArray\n* Opening brackets must be followed by a newline in multi-line arrays.\n* Closing brackets must be on their own line.\n* Elements must be indented in multi-line arrays.\n\n### Brianvarskonst.Formatting.AlphabeticalUseStatements\n* `use` statements must be sorted lexicographically.\n* Configurable sorting order via `order` property.\n\n#### Configuration\nThe `order` property of the `Brianvarskonst.Formatting.AlphabeticalUseStatements` sniff defines\nwhich function is used for ordering.\n\nPossible values for order:\n* `dictionary` (default): based on [strcmp](http://php.net/strcmp), the namespace separator\n  precedes any other character\n  ```php\n  use Doctrine\\ORM\\Query;\n  use Doctrine\\ORM\\Query\\Expr;\n  use Doctrine\\ORM\\QueryBuilder;\n  ```\n* `string`: binary safe string comparison using [strcmp](http://php.net/strcmp)\n  ```php\n  use Doctrine\\ORM\\Query;\n  use Doctrine\\ORM\\QueryBuilder;\n  use Doctrine\\ORM\\Query\\Expr;\n\n  use ExampleSub;\n  use Examples;\n  ```\n* `string-locale`: locale based string comparison using [strcoll](http://php.net/strcoll)\n* `string-case-insensitive`: binary safe case-insensitive string comparison [strcasecmp](http://php.net/strcasecmp)\n   ```php\n   use Examples;\n   use ExampleSub;\n   ```\n\nTo change the sorting order for your project, add this snippet to your custom `ruleset.xml`:\n\n```xml\n\u003crule ref=\"Brianvarskonst.Formatting.AlphabeticalUseStatements\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"order\" value=\"string-locale\"/\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\n### Brianvarskonst.Formatting.UnnecessaryNamespaceUsageSniff\n* The imported class name must be used, when it was imported with a `use` statement.\n\n### Brianvarskonst.String.VariableInDoubleQuotes\n* Interpolated variables in double-quoted strings must be surrounded by `{}`, e.g., `{$VAR}`. instead of `$VAR`.\n\n### Brianvarskonst.WhiteSpace.ConstantSpacing\n* `const` must be followed by a single space.\n\n### Brianvarskonst.WhiteSpace.MultipleEmptyLines\nSource: [mediawiki/mediawiki-codesniffer](https://github.com/wikimedia/mediawiki-tools-codesniffer)\n* No more than one empty consecutive line is allowed.\n\n### Brianvarskonst.Usage.ElementNameMinimalLength\n\n* Functions, classes, interfaces, traits, and constants must use names with a minimum length (default 3 characters).\n* Configurable via `minLength` and `allowedShortNames`.\n\n```xml\n\u003crule ref=\"Brianvarskonst.Usage.ElementNameMinimalLength\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"minLength\" value=\"5\"/\u003e\n        \u003cproperty name=\"allowedShortNames\" type=\"array\" value=\"id,db,ok,x,y\"/\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\nalternatively, whitelist can be extended via `additionalAllowedNames` config, e.g.:\n\n```xml\n\u003crule ref=\"Brianvarskonst.Usage.ElementNameMinimalLength\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"additionalAllowedNames\" type=\"array\" value=\"i,j\" /\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\n### Brianvarskonst.Complexity.NestingLevel\n\n* Ensures a maximum nesting level within functions/methods.\n* Default triggers a warning at level 3 and an error at level 5.\n* Configurable via `warningLimit` and `errorLimit`.\n\nFor example:\n\n```php\nfunction foo(bool $level_one, array $level_two, bool $level_three)\n{\n    if ($level_one) {\n        foreach ($level_two as $value) {\n            if ($level_three) {\n                return $value;\n            }\n        }\n    }\n\n    return '';\n}\n```\n\nThe example codes contains a nesting level of 3.\n\nBy default, the sniff triggers a _warning_ if nesting is equal or bigger than 3, and  triggers\nan _error_ if nesting is equal or bigger than 5.\n\nThe warning and error limit can be customized via, respectively, `warningLimit` and `errorLimit`\nproperties:\n\n```xml\n\u003crule ref=\"Brianvarskonst.Complexity.NestingLevel\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"warningLimit\" value=\"5\" /\u003e\n        \u003cproperty name=\"errorLimit\" value=\"10\" /\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\nThere's an exception. Normally a `try`/`catch`/`finally` blocks accounts for a nesting level,\nbut this sniff ignores the increase of level causes by a `try`/`catch`/`finally` that is found\nimmediately inside the level of function.\n\nFor example, the following code would be fine:\n\n```php\nfunction bar(array $data, string $foo): string\n{\n    // Indent level 1\n    try {\n        $encoded = json_encode($data, JSON_THROW_ON_ERROR);\n        // Indent level 2\n        if ($encoded) {\n            // Indent level 3\n            if ($append !== '') {\n                return $encoded . $foo;\n            }\n\n            return $encoded;\n        }\n\n        return '';\n    } catch (\\Throwable $e) {\n        return '';\n    }\n}\n```\n\nIn fact, the two nested `if`s would account for an indent level of 2, plus the `try`/`catch`\nblock that would be 3, but because the `try`/`catch` is directly inside the function it is ignored,\nso the max level considered by the sniff is 2, which is inside the limit.\n\nThis exception in the regard of `try`/`catch`/`finally` blocks can be disabled via the\n`ignoreTopLevelTryBlock` property:\n\n```xml\n\u003crule ref=\"Brianvarskonst.Complexity.NestingLevel\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"errorLimit\" value=\"10\" /\u003e\n        \u003cproperty name=\"ignoreTopLevelTryBlock\" value=\"false\" /\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\n### Brianvarskonst.Classes.PropertyPerClassLimit\n\n* Ensures a maximum number of properties per class (default 10).\n* Configurable via `maxCount`.\n\n```xml\n\u003crule ref=\"Brianvarskonst.Classes.PropertyPerClassLimit\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"maxCount\" value=\"120\" /\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\n### Brianvarskonst.Namespace.Psr4\n\n* Enforces PSR-4 autoload standards.\n* Configurable to match `composer.json` autoload settings.\n\nOur style enforce the use of PSR-4 for autoload.\nThis sniff make use of some configuration to check that files that contain classes are saved using\nthe structure expected by PSR-4.\nIf there is no configuration provided the sniff only checks that class name and match file name, which is\nnot a warranty of PSR-4.\n\nThe needed configuration is specular to the PSR-4 configuration in `composer.json` like:\n\n```json\n{\n  \"autoload\": {\n    \"psr-4\": {\n      \"Brianvarskonst\\\\Foo\\\\\": \"src/\"\n    }\n  },\n  \"autoload-dev\": {\n    \"psr-4\": {\n      \"Brianvarskonst\\\\Foo\\\\Tests\\\\\": \"tests/php/\"\n    }\n  }\n}\n```\n\nThe rule configuration should be:\n\n```xml\n\u003crule ref=\"Brianvarskonst.Namespace.Psr4\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"psr4\" type=\"array\" value=\"Brianvarskonst\\Foo=\u003esrc,Brianvarskonst\\Foo\\Tests=\u003etests/php\" /\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\nPlease note that when a PSR-4 configuration is given, *all* autoloadable entities (classes/interfaces/trait)\nare checked to be compliant.\nIf there are entities in the sniffer target paths that are not PSR-4 compliant (e.g. loaded via classmap\nor not autoloaded at all) those should be excluded via `exclude` property, e.g.:\n\n```xml\n\u003crule ref=\"Brianvarskonst.Namespace.Psr4\"\u003e\n    \u003cproperties\u003e\n        \u003cproperty name=\"psr4\" type=\"array\" value=\"Brianvarskonst\\SomeCode=\u003esrc\" /\u003e\n        \u003cproperty name=\"exclude\" type=\"array\" value=\"Brianvarskonst\\ExcludeThis,Brianvarskonst\\AndThis\" /\u003e\n    \u003c/properties\u003e\n\u003c/rule\u003e\n```\n\nNote that anything that *starts with* any of the values in the `exclude` array will be excluded.\n\nE.g. by excluding `Brianvarskonst\\ExcludeThis` things like `Brianvarskonst\\ExcludeThis\\Foo` and\n`Brianvarskonst\\ExcludeThis\\Bar\\Baz` will be excluded as well.\n\nTo make sure what's excluded is a namespace, and not a class with same name, just use `\\` as last\ncharacter.\n\n### Included rules\n\nFurther rules are imported from other standards, detailed in [`ruleset.xml`](Brianvarskonst/ruleset.xml).\n\nMost of the issues can be auto-fixed with `phpcbf`.\n\n#### PSR-1, PSR-2, PSR-12\n\nFor more information about included rules from PHP Standards Recommendations (PSR), refer to the\nofficial documentation:\n\n- [PSR-1](https://www.php-fig.org/psr/psr-1)\n- [PSR-2](https://www.php-fig.org/psr/psr-2)\n- [PSR-12](https://www.php-fig.org/psr/psr-12)\n\n#### Slevomat\n\nA few rules have been included from the [Slevomat Coding Standard](https://github.com/slevomat/coding-standard).\n\n#### Symfony\n\nA few rules have been included from the [Symfony Coding Standard](https://github.com/djoos/Symfony-coding-standard).\n\n#### Generic Rules\n\nSome rules are also included from PHP_CodeSniffer itself, as well as [PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra).\n\n## Requirements\n\n* [PHP](http://php.net)\n* [Composer](https://getcomposer.org/)\n\n## Installation\n\n### Composer\n\nUsing [Composer](https://getcomposer.org/) is the preferred way.\n\n1. Add the Brianvarskonst coding standard to `composer.json`\n\n```bash\n$ composer require --dev brianvarskonst/coding-standard\n```\n\n2. Use the coding standard:\n\n```bash\n$ ./vendor/bin/phpcs --standard=Brianvarskonst path/to/my/file.php\n```\n\n3. Optionally, set Brianvarskonst as the default coding standard:\n\n```bash\n$ ./vendor/bin/phpcs --config-set default_standard Brianvarskonst\n```\n\n### Source\n\n1. Clone the repository:\n\n```bash\n$ git clone https://github.com/brianvarskonst/coding-standard.git\n```\n\n2. Install dependencies:\n\n```\n$ composer install\n```\n\n3. Verify coding standards:\n\n```bash\n$ ./vendor/bin/phpcs -i\n```\n\n4. Use the coding standard:\n\n```bash\n$ ./vendor/bin/phpcs --standard=Brianvarskonst path/to/my/file.php\n```\n\n5. Optionally, set Brianvarskonst as the default coding standard:\n\n```\n$ ./vendor/bin/phpcs --config-set default_standard Brianvarskonst\n```\n\n## Troubleshooting\n\nIf `phpcs` complains that `Brianvarskonst` coding standard is not installed, please check the installed coding standards with\n`phpcs -i` and that `installed_paths` is set correctly with `phpcs --config-show`\n\n## Removing or Disabling Rules\n\n### Rules Tree\n\nSometimes it is necessary to not follow certain rules. To avoid error reporting, you can:\n\n- Remove rules for an entire project via configuration.\n- Disable rules from code, only in specific places.\n\nIn both cases, it is possible to remove or disable:\n\n- A complete standard\n- A standard subset\n- A single sniff\n- A single rule\n\nThese elements are in a hierarchical relationship: `standards` consist of one or more `subsets`,\nwhich contain one or more `sniffs`, which in turn contain one or more `rules`.\n\n### Removing Rules via Configuration File\n\nRules can be removed for the entire project by using a custom `phpcs.xml` file, like this:\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cruleset name=\"MyProjectCodingStandard\"\u003e\n\n    \u003crule ref=\"Brianvarskonst\"\u003e\n        \u003cexclude name=\"PSR1.Classes.ClassDeclaration\"/\u003e\n    \u003c/rule\u003e\n\n\u003c/ruleset\u003e\n```\n\nIn the example above, the `PSR1.Classes.ClassDeclaration` sniff (and all the rules it contains) has been removed.\n\nBy 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.\n\n### Removing Rules via Code Comments\n\nRemoving 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:\n\n```php\n// phpcs:disable PSR1.Classes.ClassDeclaration\n```\n\nFor 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).\n\n## IDE Integration\n\n### PhpStorm\n\nAfter installing the coding standard package as described above, configure PhpStorm to use PHP_CodeSniffer by following these steps:\n\n1. Open PhpStorm settings and navigate to:\n\u003e `Language \u0026 Frameworks` -\u003e `PHP` -\u003e `Quality Tools` -\u003e `PHP_CodeSniffer`.\n\n2. In the `Configuration` dropdown, select `Local`.\n\n3. Click the `...` button next to the dropdown to open a dialog for specifying the path to the PHP_CodeSniffer executable.\n\n4. In the file selection dialog, navigate to `vendor/bin/` in your project directory and select `phpcs`. On Windows, select `phpcs.bat`.\n\n5. 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.\n\n6. Still in the PhpStorm settings, navigate to:\n\u003e `Editor` -\u003e `Inspections`\n\n7. In the search field, type `codesniffer` and then select:\n\u003e `PHP` -\u003e `Quality Tools` -\u003e `PHP_CodeSniffer validation`\n\n8. Enable it by checking the corresponding checkbox and clicking `Apply`.\n\n9. Select `PHP_CodeSniffer validation`, then click the refresh icon next to the `Coding standard` dropdown on the right and choose `Brianvarskonst`.\n\n    - If `Brianvarskonst` is not listed, select `Custom` as the standard and use the `...` button next to the dropdown to specify the `phpcs.xml` file.\n\nOnce PhpStorm is integrated with PHP_CodeSniffer, warnings and errors will automatically be highlighted in your IDE editor.\n\n## Dependencies\n\n* [PHP CodeSniffer](https://github.com/phpcsstandards/PHP_CodeSniffer)\n* [David Joos's Symfony Coding Standard](https://github.com/djoos/Symfony-coding-standard)\n* [Composer installer for PHP_CodeSniffer coding standards](https://github.com/DealerDirect/phpcodesniffer-composer-installer)\n* [Slevomat Coding Standard](https://github.com/slevomat/coding-standard)\n* [PHPCSStandards / PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils)\n\n## Contributing\n\nSee [CONTRIBUTING.md](.github/CONTRIBUTING.md) for information.\n\n## License\n\nCopyright (c) 2024, Brianvarskonst under [MIT](LICENSE) License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianvarskonst%2Fcoding-standard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianvarskonst%2Fcoding-standard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianvarskonst%2Fcoding-standard/lists"}