{"id":14968742,"url":"https://github.com/previousnext/coding-standard","last_synced_at":"2025-06-21T23:37:23.293Z","repository":{"id":65304866,"uuid":"577953813","full_name":"previousnext/coding-standard","owner":"previousnext","description":"An enhanced coding standard for Drupal projects.","archived":false,"fork":false,"pushed_at":"2025-02-26T07:08:15.000Z","size":89,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-17T08:44:32.398Z","etag":null,"topics":["coding-standard","drupal"],"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/previousnext.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2022-12-13T22:58:53.000Z","updated_at":"2025-02-26T07:07:25.000Z","dependencies_parsed_at":"2024-06-04T09:44:11.863Z","dependency_job_id":"f0fc0c94-b38d-4ea1-8454-462cf7a7ebd8","html_url":"https://github.com/previousnext/coding-standard","commit_stats":{"total_commits":45,"total_committers":5,"mean_commits":9.0,"dds":0.4666666666666667,"last_synced_commit":"8116e70d0c854a0548ca72efc753540d1c6bfc8c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/previousnext/coding-standard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fcoding-standard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fcoding-standard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fcoding-standard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fcoding-standard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/previousnext","download_url":"https://codeload.github.com/previousnext/coding-standard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fcoding-standard/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261211682,"owners_count":23125543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["coding-standard","drupal"],"created_at":"2024-09-24T13:40:28.917Z","updated_at":"2025-06-21T23:37:18.281Z","avatar_url":"https://github.com/previousnext.png","language":"PHP","readme":"# PreviousNext Drupal Coding Standard\n\n[![Latest Stable Version](http://poser.pugx.org/previousnext/coding-standard/v)](https://packagist.org/packages/previousnext/coding-standard)\n[![Total Downloads](http://poser.pugx.org/previousnext/coding-standard/downloads)](https://packagist.org/packages/previousnext/coding-standard)\n[![GitHub branch checks state](https://img.shields.io/github/checks-status/previousnext/coding-standard/main)][ci]\n[![License](http://poser.pugx.org/previousnext/coding-standard/license)](https://packagist.org/packages/previousnext/coding-standard)\n\nThis is a PHP Codesniffer standard enhancing the [Drupal Coder][drupal-coder]\nproject. It is designed to be utilised on full Drupal site projects, rather than\ncore or contrib, or projects outside of Drupal.\n\nThe standard improves upon the Drupal standard, while maintaining the general\nstyle of Drupal.\n\nRules are loosened where static analysis tools such as PHPStan are better at\nenforcing.\n\nDocumentation rules are loosened, trusting developers to properly self describe\ncode. Suggestions to improve documentation are encouraged during human code\nreview of MR/PR's.\n\nRules added are generally those we think would be accepted by Drupal Coder\nitself.\n\nGenerally, rules that are not auto-fixable, especially documentation/commenting\nrelated, will be stripped from the ruleset.\n\nNew rules may be introduced in minor versions. You can choose to lock a version\nuntil you are ready, or utilise the baseline project.\n\n# License\n\nMIT\n\n# Transitioning\n\nConsider using the [Baseliner][php-codesniffer-baseline] project when\ntransitioning. A quick `phpcbf` beforehand will eliminate most or all problems\nbefore they are added to a baseline.\n\n```shell\ncomposer require --dev digitalrevolution/php-codesniffer-baseline\nphp bin/phpcs --report=\\\\DR\\\\CodeSnifferBaseline\\\\Reports\\\\Baseline --report-file=phpcs.baseline.xml\n```\n\nUnlike PHPStan's `reportUnmatchedIgnoredErrors`, warnings will not display when\nitems in the PHPCS baseline are resolved. Instead, work until no CS issues are\nreported with `phpcs`, then regenerate with the same baseline command above.\n\n# Using the standard\n\nUse the installer via Composer:\n\n```shell\ncomposer require dealerdirect/phpcodesniffer-composer-installer\n```\n\nInstall this project with:\n\n```shell\ncomposer require previousnext/coding-standard\n```\n\nDependencies such as Coding standard, Drupal Coder, and Slevomat Coding Standard\nwill be brought in automatically.\n\n## Configuration Template\n\nCreate a `phpcs.xml` file in a project root with the following contents:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cruleset name=\"My Coding Standard\"\u003e\n    \u003cfile\u003e./src\u003c/file\u003e\n    \u003cfile\u003e./tests\u003c/file\u003e\n    \u003cfile\u003e./app/modules/custom\u003c/file\u003e\n    \u003cfile\u003e./app/profiles/custom\u003c/file\u003e\n    \u003cfile\u003e./app/themes/custom\u003c/file\u003e\n    \u003crule ref=\"PreviousNextDrupal\" /\u003e\n    \u003carg name=\"report\" value=\"full\"/\u003e\n\u003c/ruleset\u003e\n```\n\nThis standard does not assume the location of code, so all covered paths must be\nadded to the extending ruleset.\n\n# Tips\n\nParameters and return documentation may be omitted.\nIf you intend to add typing, but do not care to document what a param or return\ndoes, then consider using `@phpstan-` prefixed annotations. Such as\n`@phpstan-param` or `@phpstan-return`.\n\n**Example**\n\nFrom _Drupal Coder_ style:\n\n```php\n/**\n * Does a thing.\n * \n * @param array $data\n *   Some data.\n * \n * @return int\n *   An integer.\n */\nfunction foo(array $data): int {\n}\n```\n\nTo:\n\nRemove useless documentation for the function/method itself. Human code review\nmust ensure the function/method/variable/param, etc, are self describing.\n\n```php\n/**\n * @phpstan-param array{bar: int} $data\n * @phpstan-return int{0, max}\n */\nfunction doesAThing(array $data): int {\n}\n```\n\n\n# Style\n\n## Added Sniffs\n\n#### PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose\n#### SlevomatCodingStandard.Classes.ClassStructure\n#### SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature\n#### SlevomatCodingStandard.Commenting.UselessInheritDocComment\n#### SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator\n#### SlevomatCodingStandard.Functions.RequireTrailingCommaInCall\n#### SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration\n#### SlevomatCodingStandard.Functions.StaticClosure\n#### SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure\n#### SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses\n#### SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions\n\nPHPStorm can be configured with Editor -\u003e General -\u003e Auto Import: _Function_: `Prefer FQN`\n\n#### SlevomatCodingStandard.TypeHints.DeclareStrictTypes\n#### SlevomatCodingStandard.TypeHints.ReturnTypeHint\n#### SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing\n#### Squiz.WhiteSpace.FunctionOpeningBraceSpace.SpacingAfter\n\n## Removed/Loosened Inherited Sniffs\n\n#### Drupal.Arrays.Array.LongLineDeclaration\n\n#### Drupal.Commenting.*\n\n * Drupal.Commenting.ClassComment.Short\n * Drupal.Commenting.DocComment.MissingShort\n * Drupal.Commenting.FileComment.Missing\n * Drupal.Commenting.FunctionComment.IncorrectParamVarName\n * Drupal.Commenting.FunctionComment.InvalidReturn\n * Drupal.Commenting.TodoComment.TodoFormat\n * Drupal.Commenting.VariableComment.Missing\n\nCommenting rules are not auto-fixable, are usually boilerplate-y.\n\nDevelopers are entrusted to properly self-describe code. Suggestions to improve documentation are encouraged during human code review of MR/PR's.\n\n#### Squiz.PHP.NonExecutableCode.Unreachable\n\nThis rule has trouble with newer PHP syntax, especially expression throwables. In any case this rule is best enforced with static analysis.\n\n---\n\n_Drupal is a registered trademark of Dries Buytaert._\n\n [ci]: https://github.com/previousnext/coding-standard/actions\n [drupal-coder]: https://www.drupal.org/project/coder\n [php-codesniffer-baseline]: https://github.com/123inkt/php-codesniffer-baseline","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreviousnext%2Fcoding-standard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpreviousnext%2Fcoding-standard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreviousnext%2Fcoding-standard/lists"}