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: 580
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 0
Open Issues: 38
Type:phpstan-extension
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: 2025-09-29 03:40:34 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
- ๐ค Contributing
- ๐ 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 |
---|---|---|
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 |
Superglobals | Discourages use of PHP superglobals | Superglobal Usage |
Control Flow
Rule | Description | Target |
---|---|---|
ElseExpression | Discourages else expressions |
Control Flow |
๐ง 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 offer additional customization options and are adapted for PHPStan's architecture and modern PHP practices.
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/Orrison/MeliorStan.git cd MeliorStan composer install composer test
Adding New Rules
- Follow the established architecture pattern
- Include comprehensive tests
- Update documentation
- Ensure all checks pass:
composer format && composer analyze && composer test
๐ 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
- PHP-Parser - AST parsing capabilities
- PHP Community - For continuous improvement of PHP tooling
Made with โค๏ธ for the PHP community
๐ Documentation โข ๐ Report Issues โข ๐ก Request Features