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.
Installs: 3 985
Dependents: 1
Suggesters: 0
Security: 0
Stars: 11
Watchers: 2
Forks: 0
Open Issues: 30
Type:phpstan-extension
pkg:composer/orrison/meliorstan
Requires
- php: ^8.3
- phpstan/phpstan: ^2.1
Requires (Dev)
- brianium/paratest: ^7.10
- friendsofphp/php-cs-fixer: ^3.76
- phpunit/phpunit: ^12.2
This package is auto-updated.
Last update: 2026-01-28 21:31:48 UTC
README
MeliorStan
Advanced PHPStan Rules for Superior Code Quality
Enhance your PHP codebase with intelligent static analysis rules that detect code smells, enforce naming conventions, and promote best practices.
๐ Table of Contents
- โจ Features
- ๐ Quick Start
- ๐ Available Rules
- ๐ง Configuration
- ๐ฏ Inspiration
- ๐ License
- ๐ Acknowledgments
โจ Features
- ๐ Comprehensive 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
๐ Quick Start
Installation
composer require --dev orrison/meliorstan
Basic Usage
Add to your phpstan.neon configuration:
includes: - vendor/orrison/meliorstan/config/extension.neon rules: - Orrison\MeliorStan\Rules\PascalCaseClassName\PascalCaseClassNameRule - Orrison\MeliorStan\Rules\CamelCaseMethodName\CamelCaseMethodNameRule
Configuration
Customize rule behavior in your phpstan.neon:
parameters: meliorstan: pascal_case_class_name: allow_consecutive_uppercase: false camel_case_method_name: allow_consecutive_uppercase: false allow_underscore_prefix: false
๐ Available Rules
Naming Conventions
| Rule | Description | Target |
|---|---|---|
| BooleanGetMethodName | Prevents get* methods from returning boolean values |
Methods |
| CamelCase Method Name | Enforces camelCase for method names | Methods |
| CamelCase Parameter Name | Enforces camelCase for parameter names | Parameters |
| CamelCase Property Name | Enforces camelCase for property names | Properties |
| CamelCase Variable Name | 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 |
| PascalCase Class Name | 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 |
| 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 |
Control Flow
| Rule | Description | Target |
|---|---|---|
| ElseExpression | Discourages else expressions |
Control Flow |
Design
| Rule | Description | Target |
|---|---|---|
| EmptyCatchBlock | Detects and reports empty catch blocks in exception handling | Catch Blocks |
| 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 |
| CyclomaticComplexity | Detects methods with high cyclomatic complexity | Methods, Classes |
| NumberOfChildren | Detects classes with too many direct child classes | Class Hierarchy |
| TooManyMethods | Detects classes with too many methods | Classes, Interfaces, Traits, Enums |
๐ง Configuration
Each rule supports extensive configuration options. Refer to individual rule documentation for detailed configuration parameters.
Global Configuration Structure
parameters: meliorstan: rule_name: option1: value1 option2: value2
Example: Comprehensive Setup
includes: - vendor/orrison/meliorstan/config/extension.neon rules: - Orrison\MeliorStan\Rules\PascalCaseClassName\PascalCaseClassNameRule - Orrison\MeliorStan\Rules\CamelCaseMethodName\CamelCaseMethodNameRule - Orrison\MeliorStan\Rules\LongClassName\LongClassNameRule parameters: meliorstan: pascal_case_class_name: allow_consecutive_uppercase: true camel_case_method_name: allow_consecutive_uppercase: false allow_underscore_prefix: false long_class_name: maximum: 50 subtract_prefixes: ["Abstract", "Base"] subtract_suffixes: ["Interface", "Trait"]
๐ฏ Inspiration
Originally inspired by PHPMD - PHP Mess Detector, this project provides modern PHPStan equivalents with enhanced configurability and PHP 8+ features.
Note: While inspired by PHPMD, these rules are not exact replicas. They may offer additional or renamed customization options and are adapted for PHPStan's architecture and modern PHP practices.
๐ค 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.
๐ Acknowledgments
- PHPStan - The foundation of modern PHP static analysis
- PHPMD - Original inspiration for code quality rules
Made with โค๏ธ for the PHP community