epifrin/rector-custom-rules
最新稳定版本:0.5.1
Composer 安装命令:
composer require epifrin/rector-custom-rules
包简介
These are three rector rules to convert private method name, to convert local variable name to camel case and to replace double quotes with single quotes in string literals.
README 文档
README
These are three rector rules to convert private method name, to convert local variable name to camel case and to replace double quotes with single quotes in string literals.
Installation
composer require --dev epifrin/rector-custom-rules
Usage
Add the following to your rector config:
$rectorConfig->rule(\Epifrin\RectorCustomRules\RectorRules\ConvertPrivateMethodsNameToCamelCaseRector::class); $rectorConfig->rule(\Epifrin\RectorCustomRules\RectorRules\ConvertLocalVariablesNameToCamelCaseRector::class); $rectorConfig->rule(\Epifrin\RectorCustomRules\RectorRules\ReplaceDoubleQuotesWithSingleRector::class);
Rector rules
Convert local variable names to camel case
class SomeClass
{
public function aMethod()
{
- $my_variable = 1;
+ $myVariable = 1;
- return $my_variable;
+ return $myVariable;
}
}
Convert private method names to camel case
Why only private methods? Because it's safer to change private method names than public or protected method names.
class SomeClass
{
public function publicMethod()
{
- $this->my_private_method();
+ $this->myPrivateMethod();
- self::my_static_private_method();
+ self::myStaticPrivateMethod();
}
- private function my_private_method() {}
+ private function myPrivateMethod() {}
- private static function my_static_private_method() {}
+ private static function myStaticPrivateMethod() {}
}
Replace double quotes with single
This rule replaces double quotes with single quotes in string literals. It does not replace double quotes if the string literal contains variables or substitutions.
Here is an example of how this rule works:
class SomeClass
{
public function someMethod()
{
- $string = "This is a simple string";
+ $string = 'This is a simple string';
- $stringWithVariable = "Hello, $name";
+ $stringWithVariable = "Hello, $name";
- $stringWithSpecialChar = "String with special char: \n";
+ $stringWithSpecialChar = "String with special char: \n";
}
}
统计信息
- 总下载量: 26.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-06