previousnext/coding-standard
Composer 安装命令:
composer require previousnext/coding-standard
包简介
README 文档
README
This is a PHP Codesniffer standard enhancing the Drupal Coder project. It is designed to be utilised on full Drupal site projects, rather than core or contrib, or projects outside of Drupal.
The standard improves upon the Drupal standard, while maintaining the general style of Drupal.
Rules are loosened where static analysis tools such as PHPStan are better at enforcing.
Documentation rules are loosened, trusting developers to properly self describe code. Suggestions to improve documentation are encouraged during human code review of MR/PR's.
Rules added are generally those we think would be accepted by Drupal Coder itself.
Generally, rules that are not auto-fixable, especially documentation/commenting related, will be stripped from the ruleset.
New rules may be introduced in minor versions. You can choose to lock a version until you are ready, or utilise the baseline project.
License
MIT
Transitioning
Consider using the Baseliner project when
transitioning. A quick phpcbf beforehand will eliminate most or all problems
before they are added to a baseline.
composer require --dev digitalrevolution/php-codesniffer-baseline php bin/phpcs --report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --report-file=phpcs.baseline.xml
Unlike PHPStan's reportUnmatchedIgnoredErrors, warnings will not display when
items in the PHPCS baseline are resolved. Instead, work until no CS issues are
reported with phpcs, then regenerate with the same baseline command above.
Using the standard
Use the installer via Composer:
composer require dealerdirect/phpcodesniffer-composer-installer
Install this project with:
composer require previousnext/coding-standard
Dependencies such as Coding standard, Drupal Coder, and Slevomat Coding Standard will be brought in automatically.
Configuration Template
Create a phpcs.xml file in a project root with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="My Coding Standard"> <file>./src</file> <file>./tests</file> <file>./app/modules/custom</file> <file>./app/profiles/custom</file> <file>./app/themes/custom</file> <rule ref="PreviousNextDrupal" /> <arg name="report" value="full"/> </ruleset>
This standard does not assume the location of code, so all covered paths must be added to the extending ruleset.
Tips
Parameters and return documentation may be omitted.
If you intend to add typing, but do not care to document what a param or return
does, then consider using @phpstan- prefixed annotations. Such as
@phpstan-param or @phpstan-return.
Example
From Drupal Coder style:
/** * Does a thing. * * @param array $data * Some data. * * @return int * An integer. */ function foo(array $data): int { }
To:
Remove useless documentation for the function/method itself. Human code review must ensure the function/method/variable/param, etc, are self describing.
/** * @phpstan-param array{bar: int} $data * @phpstan-return int{0, max} */ function doesAThing(array $data): int { }
Style
Added Sniffs
PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose
SlevomatCodingStandard.Classes.ClassStructure
SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature
SlevomatCodingStandard.Commenting.UselessInheritDocComment
SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator
SlevomatCodingStandard.Functions.RequireTrailingCommaInCall
SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration
SlevomatCodingStandard.Functions.StaticClosure
SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure
SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions
PHPStorm can be configured with Editor -> General -> Auto Import: Function: Prefer FQN
SlevomatCodingStandard.TypeHints.DeclareStrictTypes
SlevomatCodingStandard.TypeHints.ReturnTypeHint
SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing
Squiz.WhiteSpace.FunctionOpeningBraceSpace.SpacingAfter
Removed/Loosened Inherited Sniffs
Drupal.Arrays.Array.LongLineDeclaration
Drupal.Commenting.*
- Drupal.Commenting.ClassComment.Short
- Drupal.Commenting.DocComment.MissingShort
- Drupal.Commenting.FileComment.Missing
- Drupal.Commenting.FunctionComment.IncorrectParamVarName
- Drupal.Commenting.FunctionComment.InvalidReturn
- Drupal.Commenting.TodoComment.TodoFormat
- Drupal.Commenting.VariableComment.Missing
Commenting rules are not auto-fixable, are usually boilerplate-y.
Developers are entrusted to properly self-describe code. Suggestions to improve documentation are encouraged during human code review of MR/PR's.
Squiz.PHP.NonExecutableCode.Unreachable
This rule has trouble with newer PHP syntax, especially expression throwables. In any case this rule is best enforced with static analysis.
Drupal is a registered trademark of Dries Buytaert.
previousnext/coding-standard 适用场景与选型建议
previousnext/coding-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50.28k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「drupal」 「phpcs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 previousnext/coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 previousnext/coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 previousnext/coding-standard 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides an add-on purchasable entity.
The coding standard applying to all Youdot PHP projects, based on Doctrine set of PHPCS rules, with additional checks.
Drupal integration module for the Kalastatic prototyping and styleguide tool
Provides a base set of configuration and module dependencies for starting new Drupal projects.
CodeSniffer ruleset for the ZettaCMS coding standard
This module extends Drupal Migrate framework.
统计信息
- 总下载量: 50.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 26
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-16