guanguans / rector-rules
A set of additional rules for rector/rector. - 一套针对 `rector/rector` 的附加规则。
Fund package maintenance!
Sponsors
Installs: 784
Dependents: 7
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/guanguans/rector-rules
Requires
- php: >=7.4
- illuminate/support: ^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0
- rector/rector: ^2.3
- symfony/polyfill-php80: ^1.33
- symfony/polyfill-php81: ^1.33
- webmozart/assert: ^1.12 || ^2.0
Requires (Dev)
- adamwojs/php-cs-fixer-phpdoc-force-fqcn: ^2.0
- bamarni/composer-bin-plugin: ^1.9
- brainmaestro/composer-git-hooks: ^2.8 || ^3.0
- composer/composer: ^2.9
- driftingly/rector-laravel: ^2.1
- ergebnis/composer-normalize: ^2.49
- ergebnis/license: ^2.7
- ergebnis/php-cs-fixer-config: ^6.59
- ergebnis/rector-rules: ^1.9
- fakerphp/faker: ^1.24
- guanguans/php-cs-fixer-custom-fixers: ^1.1
- guanguans/phpstan-rules: ^1.0
- mockery/mockery: ^1.6
- nette/utils: ^3.2 || ^4.0
- pestphp/pest: ^1.23 || ^2.0 || ^3.0 || ^4.0
- php-mock/php-mock-phpunit: ^2.14
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-mockery: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-webmozart-assert: ^2.0
- phpunit/phpunit: ^9.6 || ^10.0 || ^11.0 || ^12.0
- povils/phpmnd: ^3.6
- rector/argtyper: ^0.6
- rector/jack: ^0.5
- rector/swiss-knife: ^2.3
- rector/type-perfect: ^2.1
- shipmonk/composer-dependency-analyser: ^1.8
- shipmonk/dead-code-detector: ^0.14
- shipmonk/name-collision-detector: ^2.1
- shipmonk/phpstan-baseline-per-identifier: ^2.3
- spatie/pest-plugin-snapshots: ^1.1 || ^2.0
- spaze/phpstan-disallowed-calls: ^4.7
- staabm/phpstan-todo-by: ^0.3
- symfony/thanks: ^1.3
- symfony/var-dumper: ^5.4 || ^6.0 || ^7.0 || ^8.0
- symplify/phpstan-rules: ^14.9
- tomasvotruba/class-leak: ^2.1
- tomasvotruba/cognitive-complexity: ^1.0
- tomasvotruba/ctor: ^2.2
- tomasvotruba/type-coverage: ^2.1
- tomasvotruba/unused-public: ^2.2
- yamadashy/phpstan-friendly-formatter: ^1.2
README
Note
A set of additional rules for rector/rector. - 一套针对 rector/rector 的附加规则。
Requirement
- PHP >= 7.4
Installation
composer require guanguans/rector-rules --dev --ansi -v
Usage
🧐 Rules Overview
🧐 Sets Overview
Guanguans\RectorRules\Set\SetList::ALLGuanguans\RectorRules\Set\SetList::COMMONGuanguans\RectorRules\Set\SetList::GUZZLEGuanguans\RectorRules\Set\SetList::LARAVELGuanguans\RectorRules\Set\SetList::PESTGuanguans\RectorRules\Set\SetList::PHPBENCHGuanguans\RectorRules\Set\SetList::PHPSTANGuanguans\RectorRules\Set\SetList::RECTORGuanguans\RectorRules\Set\SetList::SYMFONY
In your rector configuration register rules
use Guanguans\RectorRules\Rector\File\SortFileFunctionStmtRector; use Guanguans\RectorRules\Rector\FunctionLike\RenameGarbageParamNameRector; use Guanguans\RectorRules\Rector\Name\RenameToConventionalCaseNameRector; use PhpParser\NodeVisitor\ParentConnectingVisitor; use Rector\Config\RectorConfig; return RectorConfig::configure() ->withSets([ Guanguans\RectorRules\Set\SetList::ALL, // ... ]) // ... ->registerDecoratingNodeVisitor(ParentConnectingVisitor::class) ->withConfiguredRule(RenameToConventionalCaseNameRector::class, [ 'assertMatches*Snapshot', // Exclude `spatie/pest-plugin-snapshots` function name 'beforeEach', // Exclude `pestphp/pest` function name 'PDO', // Exclude `ext-pdo` class name ]) // ... ->withRules([ RenameGarbageParamNameRector::class, SortFileFunctionStmtRector::class, // ... ]);
Example of RenameToConventionalCaseNameRector
/** @noinspection ALL */ // @formatter:off // phpcs:ignoreFile // lower snake -use function functionName; -function functionName(){} -functionName(); -call_user_func('functionName'); -call_user_func_array('functionName', []); -function_exists('functionName'); +use function function_name; +function function_name(){} +\function_name(); +call_user_func('function_name'); +call_user_func_array('function_name', []); +function_exists('function_name'); // ucfirst camel // #[attribute_name()] -class class_name{} +class ClassName{} // enum enum_name{} // enum Enum{case case_name;} -interface interface_name{} -trait trait_name{} -class Foo extends class_name implements interface_name{} -class_name::$property; -class_name::CONST; -class_name::method(); +interface InterfaceName{} +trait TraitName{} +class Foo extends \ClassName implements \InterfaceName{} +\ClassName::$property; +\ClassName::CONST; +\ClassName::method(); // enum Enum implements interface_name{} -use class_name; -use trait_name; -class_alias('class_name', 'alias_class_name'); -class_alias($className, 'alias_class_name'); -class_exists('class_name'); -class_implements('class_name'); -class_parents('class_name'); -class_uses('class_name'); -enum_exists('enum_name'); -get_class_methods('class_name'); -get_class_vars('class_name'); -get_parent_class('class_name'); -interface_exists('interface_name'); -is_subclass_of('class_name', 'parent_class_name'); -is_subclass_of($className, 'parent_class_name'); -trait_exists('trait_name', true); +use ClassName; +use TraitName; +class_alias('ClassName', 'AliasClassName'); +class_alias($className, 'AliasClassName'); +class_exists('ClassName'); +class_implements('ClassName'); +class_parents('ClassName'); +class_uses('ClassName'); +enum_exists('EnumName'); +get_class_methods('ClassName'); +get_class_vars('ClassName'); +get_parent_class('ClassName'); +interface_exists('InterfaceName'); +is_subclass_of('ClassName', 'ParentClassName'); +is_subclass_of($className, 'ParentClassName'); +trait_exists('TraitName', true); // upper snake -use const constName; -class Foo{public const constName = 'const';} -Foo::constName; -define('constName', 'const'); -defined('constName'); -constant('constName'); -constant('Foo::constName'); -constName; +use const CONST_NAME; +class Foo{public const CONST_NAME = 'const';} +Foo::CONST_NAME; +define('CONST_NAME', 'const'); +defined('CONST_NAME'); +constant('CONST_NAME'); +constant('Foo::CONST_NAME'); +\CONST_NAME; // lcfirst camel -$var_name; -$object->method_name(); -$object->property_name; -call_user_method('method_name', $object); -call_user_method_array('method_name', $object); -class Foo{public $property_name;} -class Foo{public function method_name(){}} -class Foo{public int $property_name;} -Foo::$property_name; -Foo::method_name(); -method_exists($object, 'method_name'); -property_exists($object, 'property_name'); +$varName; +$object->methodName(); +$object->propertyName; +call_user_method('methodName', $object); +call_user_method_array('methodName', $object); +class Foo{public $propertyName;} +class Foo{public function methodName(){}} +class Foo{public int $propertyName;} +Foo::$propertyName; +Foo::methodName(); +method_exists($object, 'methodName'); +property_exists($object, 'propertyName');
Composer scripts
composer checks:required
composer php-cs-fixer:fix
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.