定制 orrison/meliorstan 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

orrison/meliorstan

最新稳定版本:v0.4.0

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 Superior Code Quality

Enhance your PHP codebase with intelligent static analysis rules that detect code smells, enforce naming conventions, and promote best practices.

Latest Stable Version Total Downloads License PHP Version PHPStan

???? Table of Contents

✨ 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 offer additional customization options and are adapted for PHPStan's architecture and modern PHP practices.

Development Setup

git clone https://github.com/Orrison/MeliorStan.git
cd MeliorStan
composer install
composer test

Adding New Rules

  1. Follow the established architecture pattern
  2. Include comprehensive tests
  3. Update documentation
  4. 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

统计信息

  • 总下载量: 3.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固