orrison/meliorstan
Composer 安装命令:
composer require orrison/meliorstan
包简介
Provides PHPStan rules for improved code quality by detecting code smells and possible issues. In addition to enforcing particular naming and code style conventions to reduce bike-shedding.
关键字:
README 文档
README
MeliorStan
Advanced PHPStan Rules for Code Quality and Consistency
Enhance your PHP codebase with intelligent static analysis rules that detect code smells, enforce naming conventions, and promote best practices.
Table of Contents
Features
- Code Analysis: Detect code smells and potential issues
- Naming Convention Enforcement: Ensure consistent naming across your codebase
- Highly Configurable: Customize rules to match your project's standards
- Modern PHP Support: Built for PHP 8.3+ with PHPStan 2.1+
- Extensive Documentation: Detailed guides for each rule
- Well Tested: Comprehensive test suite ensuring reliability
Configuration and Usage
Install the package:
composer require --dev orrison/meliorstan
MeliorStan does not auto-register any rules. Including vendor/orrison/meliorstan/config/extension.neon only loads the parameter schemas and config services that the rules need. There is no phpstan/extension-installer integration, so every rule you want to run must be listed explicitly under rules: in your PHPStan config. This is intentional: each rule is opt-in so you can pick only the ones that fit your project.
A minimal phpstan.neon enabling and configuring two rules looks like this:
includes: - vendor/orrison/meliorstan/config/extension.neon rules: - Orrison\MeliorStan\Rules\PascalCaseClassName\PascalCaseClassNameRule - Orrison\MeliorStan\Rules\CamelCaseMethodName\CamelCaseMethodNameRule parameters: meliorstan: pascal_case_class_name: allow_consecutive_uppercase: false camel_case_method_name: allow_consecutive_uppercase: false allow_underscore_prefix: false
Add or remove entries under rules: to control which checks run. Each rule's available options, defaults, and behavior are documented on its own page, linked from Available Rules below.
Available Rules
Naming Conventions
| Rule | Description | Target |
|---|---|---|
| BooleanGetMethodName | Prevents get* methods from returning boolean values |
Methods |
| CamelCaseMethodName | Enforces camelCase for method names | Methods |
| CamelCaseParameterName | Enforces camelCase for parameter names | Parameters |
| CamelCasePropertyName | Enforces camelCase for property names | Properties |
| CamelCaseVariableName | Enforces camelCase for variable names | Variables |
| ConstantNamingConventions | Enforces UPPERCASE for constants | Constants |
| ConstructorWithNameAsEnclosingClass | Prevents methods with same name as their class | Methods |
| LongClassName | Limits class/interface/trait/enum name length | Classes, Interfaces, Traits, Enums |
| PascalCaseClassName | Enforces PascalCase for class names | Classes |
| ShortClassName | Enforces minimum class/interface/trait/enum name length | Classes, Interfaces, Traits, Enums |
| TraitConstantNamingConventions | Enforces UPPERCASE for trait constants | Trait Constants |
Code Quality
| Rule | Description | Target |
|---|---|---|
| BooleanArgumentFlag | Detects boolean parameters in functions and methods that may indicate multiple responsibilities | Methods, Functions, Closures |
| LongVariable | Limits variable name length | Variables |
| MissingClosureParameterTypehint | Requires type hints on closure parameters | Closures |
| MissingImport | Detects types referenced by fully qualified name instead of being imported with a use statement |
Type-reference positions |
| ShortMethodName | Enforces minimum method name length | Methods |
| ShortVariable | Enforces minimum variable name length | Variables |
| ForbidPestPhpOnly | Prevents committed Pest tests from using the only() filter |
Tests |
| Superglobals | Discourages use of PHP superglobals | Superglobal Usage |
| UnusedFormalParameter | Detects function/method/closure parameters that are declared but never used | Function/method/closure parameters |
| UnusedLocalVariable | Detects local variables assigned but never read inside a function/method/closure | Local Variables |
Control Flow
| Rule | Description | Target |
|---|---|---|
| ElseExpression | Discourages else expressions |
Control Flow |
| IfStatementAssignment | Detects assignments inside if and elseif conditions |
Control Flow |
Design
| Rule | Description | Target |
|---|---|---|
| DevelopmentCodeFragment | Detects calls to development/debug functions like var_dump, print_r, etc. | Function Calls |
| EmptyCatchBlock | Detects and reports empty catch blocks in exception handling | Catch Blocks |
| ErrorControlOperator | Detects use of the error control operator (@), which silently suppresses errors instead of handling them properly | Error Suppression |
| ForbidCountInLoopExpressions | Detects usage of count() or sizeof() in loop conditions | Loop Conditions |
| ForbidEvalExpressions | Detects and reports usage of eval expressions | Eval Expressions |
| ForbidExitExpressions | Detects and reports usage of exit and die expressions | Exit Expressions |
| ForbidGotoStatements | Detects and reports usage of goto statements | Goto Statements |
| CouplingBetweenObjects | Detects classes with too many type dependencies | Classes, Interfaces, Traits, Enums |
| DepthOfInheritance | Detects classes with excessively deep inheritance chains | Classes |
| ExcessiveClassLength | Detects classes, interfaces, traits, and enums with excessive line counts | Classes, Interfaces, Traits, Enums |
| ExcessiveMethodLength | Detects methods, functions, and closures with excessive line counts | Methods, Functions, Closures |
| ExcessiveClassComplexity | Detects classes with excessive total cyclomatic complexity (Weighted Method Count) | Classes, Interfaces, Traits, Enums |
| ExcessiveParameterList | Detects functions, methods, closures, and arrow functions with too many parameters | Functions, Methods, Closures, Arrow Functions |
| ExcessivePublicCount | Detects classes with an excessive public API surface (public methods + properties) | Classes, Interfaces, Traits, Enums |
| CyclomaticComplexity | Detects methods, functions, and classes with high cyclomatic complexity | Methods, Functions, Classes |
| NpathComplexity | Detects methods and functions with high NPath complexity (number of acyclic execution paths) | Methods, Functions |
| CognitiveComplexity | Detects methods, functions, and classes with high Cognitive Complexity, the SonarSource understandability metric with a nesting penalty | Methods, Functions, Classes |
| NumberOfChildren | Detects classes with too many direct child classes | Class Hierarchy |
| StaticAccess | Detects static method calls and optionally static property access that create tight coupling | Static Access |
| TooManyFields | Detects classes and traits with an excessive number of instance fields | Classes, Traits |
| TooManyMethods | Detects classes with too many methods | Classes, Interfaces, Traits, Enums |
| TooManyPublicMethods | Detects classes with too many public methods | Classes, Interfaces, Traits, Enums |
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
AI Disclosure
AI assistants (Claude and similar tools) are used variably in the development and maintenance of this project, including for research, planning, drafting documentation, and at times generating or refactoring code. A significant portion of the code is still written by hand, and all code, tests, and documentation are reviewed, edited, and approved by human maintainers and contributors before being committed or released. The maintainers and contributors are the authors of, and are fully accountable for, everything in this repository. If you find a bug or quality issue, treat it as a project issue and report it normally; AI involvement is never an excuse.
Acknowledgments
- PHPStan: the foundation of modern PHP static analysis that MeliorStan builds on.
- PHPMD - PHP Mess Detector: the original inspiration for many of the code quality rules. MeliorStan is not a direct 1:1 port; overlapping rules have diverged in behavior and configuration. See MeliorStan and PHPMD for more information.
orrison/meliorstan 适用场景与选型建议
orrison/meliorstan 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.54k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2025 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「PHPStan」 「phpstan-rules」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 orrison/meliorstan 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 orrison/meliorstan 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 orrison/meliorstan 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides rules for phpstan/phpstan.
Services to aid phpstan analysis on CakePHP projects
Doctrine Criteria extensions for PHPStan
PHPStan for Silverstripe
PHPStan extensions for Containers
PHPStan extension with opinionated strict rules for better code in tests.
统计信息
- 总下载量: 17.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-16