mi-schi/phpmd-extension
Composer 安装命令:
composer require mi-schi/phpmd-extension
包简介
Contains extra phpmd rules from clean code book and the best practices of my experiences.
README 文档
README
Features
Contains extra phpmd rules from clean code book and the best practices of my experiences.
- CleanCode
- ConditionalExpression - increase readability
- ConstructorNewOperator - decouple classes, see open-close principle
- DataStructureConstants - increase maintainability
- DataStructureMethods - increase extensibility, see single-responsibility principle
- MemberPrimaryPrefix - supports low coupling, increase testability, see law of demeter
- PublicFieldDeclaration - increase maintainability, see encapsulation/information hiding
- ReturnStatement - increase reading rate, increase extensibility
- SwitchStatement - increase extensibility, see open-close principle
- TraitPublicMethod - increase maintainability, see encapsulation/information hiding
- TryStatement - increase readability
- PrivateFieldDeclaration - supports high cohesion, see DRY and single-responsibility principle
- Naming
- ClassNameSuffix - increase extensibility, see single-responsibility principle
- CommentDescription - reduce unused declarations, increase comprehensibility
- MethodName - increase readability, increase comprehensibility
- Test
- NumberOfMocks - increase testability, supports low coupling, see single-responsibility principle
- NumberOfAsserts - increase maintainability, speed up debugging, see single-responsibility principle
- MethodName - increase readability, increase comprehensibility
Installation
Download the phpmd-extension.phar:
$ curl -OsL https://github.com/mi-schi/phpmd-extension/releases/download/stable/phpmd-extension.phar
Alternatively you can use tooly-composer-script for installation.
It is also possible to use composer (not recommended, see #5):
composer require mi-schi/phpmd-extension --dev
Usage
- Create a
phpmd.xmlfile and import the basic rules from phpmd. The example below contains some useful changes. Afterwards you can extend the configuration with rules from this repository. - Then execute the mess detection with
phpmd-extension.phar [path/to/src] xml [path/to/phpmd.xml]. Thephpmd-extension.pharpass all arguments to the basic phpmd command. You don't have to install phpmd.phpmd-extension.pharincludes phpmd.
Basic Rules
<ruleset name="basic-rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <description>mess detection</description> <rule ref="rulesets/cleancode.xml" /> <rule ref="rulesets/codesize.xml"> <exclude name="ExcessiveParameterList" /> <exclude name="ExcessiveMethodLength" /> <exclude name="ExcessiveClassLength" /> <exclude name="CyclomaticComplexity" /> </rule> <rule ref="rulesets/codesize.xml/ExcessiveParameterList"> <properties> <property name="minimum" value="4" /> </properties> </rule> <rule ref="rulesets/codesize.xml/ExcessiveMethodLength"> <properties> <property name="minimum" value="31" /> <property name="ignore-whitespace" value="true" /> </properties> </rule> <rule ref="rulesets/codesize.xml/ExcessiveClassLength"> <properties> <property name="minimum" value="301" /> <property name="ignore-whitespace" value="true" /> </properties> </rule> <rule ref="rulesets/codesize.xml/CyclomaticComplexity"> <properties> <property name="reportLevel" value="6" /> <property name="showClassesComplexity" value="true" /> <property name="showMethodsComplexity" value="true" /> </properties> </rule> <rule ref="rulesets/controversial.xml" /> <rule ref="rulesets/design.xml" /> <rule ref="rulesets/naming.xml"> <exclude name="ShortVariable" /> <exclude name="LongVariable" /> </rule> <rule ref="rulesets/naming.xml/ShortVariable"> <properties> <property name="minimum" value="2" /> </properties> </rule> <rule ref="rulesets/naming.xml/LongVariable"> <properties> <property name="maximum" value="30" /> </properties> </rule> <rule ref="rulesets/unusedcode.xml" /> </ruleset>
Add extra rules
<rule ref="../../../../../../rulesets/cleancode.xml" /> <rule ref="../../../../../../rulesets/naming.xml" /> <rule ref="../../../../../../rulesets/test.xml" />
You can also customize the rules with own properties or use only specific rules. Just take a look in the xml files. It works as the basic ruleset logic.
Exclude or customize extra rule
If you don't want the Law-of-Demeter rule MemberPrimaryPrefix exclude it.
<rule ref="../../../../../../rulesets/cleancode.xml"> <exclude name="MemberPrimaryPrefix" /> </rule>
If you want to customize it, use the following code:
<rule ref="../../../../../../rulesets/cleancode.xml/MemberPrimaryPrefix"> <properties> <property name="maxChainCount" value="3" description="max count of method chains" /> <property name="allowedPrefixes" value="add,set" description="allowed prefixes for the method train" /> <property name="delimiter" value="," description="delimiter for explode" /> </properties> </rule>
mi-schi/phpmd-extension 适用场景与选型建议
mi-schi/phpmd-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 902.26k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2017 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「rules」 「phpmd」 「best practices」 「mess detection」 「clean code」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mi-schi/phpmd-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mi-schi/phpmd-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mi-schi/phpmd-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shim repository for phpmd/phpmd
A custom URL rule class for Yii 2 which allows to create translated URL rules
This is the ZooRoyal coding standard.
Programic Quality Control package
Magento 2 module which adds support for Speculation Rules API for instant page loads.
Jeux de règles pour PHP Mess Detector.
统计信息
- 总下载量: 902.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 40
- 点击次数: 30
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-23