rector/docs/AllRectorsOverview.md

4382 lines
84 KiB
Markdown
Raw Normal View History

2018-05-04 22:30:32 +00:00
# All Rectors Overview
2018-04-29 09:03:47 +00:00
2018-08-01 20:09:34 +00:00
- [Projects](#projects)
- [General](#general)
## Projects
2018-09-28 16:33:35 +00:00
- [CakePHP\MethodCall](#cakephpmethodcall)
2018-10-21 22:26:45 +00:00
- [CodeQuality\Assign](#codequalityassign)
- [CodeQuality\BinaryOp](#codequalitybinaryop)
- [CodeQuality\BooleanAnd](#codequalitybooleanand)
2019-01-03 12:47:44 +00:00
- [CodeQuality\Concat](#codequalityconcat)
2018-10-21 22:26:45 +00:00
- [CodeQuality\Foreach_](#codequalityforeach_)
- [CodeQuality\FuncCall](#codequalityfunccall)
- [CodeQuality\Identical](#codequalityidentical)
- [CodeQuality\If_](#codequalityif_)
- [CodeQuality\LogicalOr](#codequalitylogicalor)
- [CodeQuality\Return_](#codequalityreturn_)
2018-10-21 22:26:45 +00:00
- [CodeQuality\Ternary](#codequalityternary)
- [CodingStyle\ClassConst](#codingstyleclassconst)
- [CodingStyle\ClassMethod](#codingstyleclassmethod)
- [CodingStyle\FuncCall](#codingstylefunccall)
- [CodingStyle\Identical](#codingstyleidentical)
- [CodingStyle\If_](#codingstyleif_)
- [CodingStyle\Switch_](#codingstyleswitch_)
- [CodingStyle\Use_](#codingstyleuse_)
2018-12-25 19:55:16 +00:00
- [DeadCode\Array_](#deadcodearray_)
- [DeadCode\Assign](#deadcodeassign)
- [DeadCode\ClassMethod](#deadcodeclassmethod)
2018-12-31 11:50:32 +00:00
- [DeadCode\Expression](#deadcodeexpression)
2018-12-25 19:55:16 +00:00
- [DeadCode\Foreach_](#deadcodeforeach_)
- [DeadCode\Property](#deadcodeproperty)
- [DeadCode\StaticCall](#deadcodestaticcall)
- [DeadCode\Stmt](#deadcodestmt)
2018-08-01 20:09:34 +00:00
- [Doctrine](#doctrine)
2018-12-14 19:35:35 +00:00
- [DomainDrivenDesign\ObjectToScalar](#domaindrivendesignobjecttoscalar)
- [Guzzle\MethodCall](#guzzlemethodcall)
2018-10-21 22:26:45 +00:00
- [Jms\Property](#jmsproperty)
2019-02-02 16:22:15 +00:00
- [NetteToSymfony](#nettetosymfony)
- [PHPStan\Assign](#phpstanassign)
- [PHPStan\Cast](#phpstancast)
2018-07-31 21:47:59 +00:00
- [PHPUnit](#phpunit)
2018-10-21 22:26:45 +00:00
- [PHPUnit\Foreach_](#phpunitforeach_)
2018-12-14 19:35:35 +00:00
- [PHPUnit\MethodCall](#phpunitmethodcall)
2018-07-31 21:47:59 +00:00
- [PHPUnit\SpecificMethod](#phpunitspecificmethod)
2018-08-01 20:09:34 +00:00
- [PhpParser](#phpparser)
2018-10-12 23:15:00 +00:00
- [Php\Assign](#phpassign)
- [Php\BinaryOp](#phpbinaryop)
- [Php\ClassConst](#phpclassconst)
- [Php\ConstFetch](#phpconstfetch)
2019-01-22 20:34:38 +00:00
- [Php\Double](#phpdouble)
2018-10-12 23:15:00 +00:00
- [Php\Each](#phpeach)
- [Php\FuncCall](#phpfunccall)
- [Php\FunctionLike](#phpfunctionlike)
2018-12-31 19:29:12 +00:00
- [Php\If_](#phpif_)
2018-10-12 23:15:00 +00:00
- [Php\List_](#phplist_)
2018-12-31 11:50:32 +00:00
- [Php\MagicConstClass](#phpmagicconstclass)
2018-12-31 19:29:12 +00:00
- [Php\MethodCall](#phpmethodcall)
2018-10-12 23:15:00 +00:00
- [Php\Name](#phpname)
- [Php\Property](#phpproperty)
2018-12-31 11:50:32 +00:00
- [Php\StaticCall](#phpstaticcall)
2018-10-21 22:26:45 +00:00
- [Php\String_](#phpstring_)
- [Php\Switch_](#phpswitch_)
2018-10-12 23:15:00 +00:00
- [Php\Ternary](#phpternary)
- [Php\TryCatch](#phptrycatch)
2018-10-21 22:26:45 +00:00
- [Php\Unset_](#phpunset_)
2018-08-01 20:09:34 +00:00
- [Sensio\FrameworkExtraBundle](#sensioframeworkextrabundle)
2018-09-28 16:33:35 +00:00
- [Silverstripe](#silverstripe)
2018-07-31 21:47:59 +00:00
- [Sylius\Review](#syliusreview)
- [Symfony\Console](#symfonyconsole)
2018-08-01 20:09:34 +00:00
- [Symfony\Controller](#symfonycontroller)
2018-07-31 21:47:59 +00:00
- [Symfony\DependencyInjection](#symfonydependencyinjection)
- [Symfony\Form](#symfonyform)
2018-08-01 20:09:34 +00:00
- [Symfony\FrameworkBundle](#symfonyframeworkbundle)
- [Symfony\HttpKernel](#symfonyhttpkernel)
2018-10-21 22:26:45 +00:00
- [Symfony\MethodCall](#symfonymethodcall)
- [Symfony\New_](#symfonynew_)
2018-07-31 21:47:59 +00:00
- [Symfony\Process](#symfonyprocess)
2018-08-01 20:09:34 +00:00
- [Symfony\Validator](#symfonyvalidator)
- [Symfony\VarDumper](#symfonyvardumper)
- [Symfony\Yaml](#symfonyyaml)
2018-09-28 16:33:35 +00:00
- [Twig](#twig)
## CakePHP\MethodCall
### `ModalToGetSetRector`
- class: `Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector`
Changes combined set/get `value()` to specific `getValue()` or `setValue(x)`.
```diff
$object = new InstanceConfigTrait;
-$config = $object->config();
-$config = $object->config('key');
+$config = $object->getConfig();
+$config = $object->getConfig('key');
-$object->config('key', 'value');
-$object->config(['key' => 'value']);
+$object->setConfig('key', 'value');
+$object->setConfig(['key' => 'value']);
```
2018-08-01 20:09:34 +00:00
<br>
2018-10-21 22:26:45 +00:00
## CodeQuality\Assign
### `CombinedAssignRector`
- class: `Rector\CodeQuality\Rector\Assign\CombinedAssignRector`
Simplify $value = $value + 5; assignments to shorter ones
```diff
-$value = $value + 5;
+$value += 5;
```
<br>
## CodeQuality\BinaryOp
### `SimplifyDeMorganBinaryRector`
- class: `Rector\CodeQuality\Rector\BinaryOp\SimplifyDeMorganBinaryRector`
Simplify negated conditions with de Morgan theorem
```diff
<?php
$a = 5;
$b = 10;
-$result = !($a > 20 || $b <= 50);
+$result = $a <= 20 && $b > 50;
```
<br>
## CodeQuality\BooleanAnd
### `SimplifyEmptyArrayCheckRector`
- class: `Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector`
Simplify `is_array` and `empty` functions combination into a simple identical check for an empty array
```diff
-is_array($values) && empty($values)
+$values === []
```
<br>
2019-01-03 12:47:44 +00:00
## CodeQuality\Concat
### `JoinStringConcatRector`
- class: `Rector\CodeQuality\Rector\Concat\JoinStringConcatRector`
Joins concat of 2 strings
```diff
class SomeClass
{
public function run()
{
- $name = 'Hi' . ' Tom';
+ $name = 'Hi Tom';
}
}
```
<br>
2018-10-21 22:26:45 +00:00
## CodeQuality\Foreach_
2018-10-23 18:58:57 +00:00
### `ForeachToInArrayRector`
- class: `Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector`
Simplify `foreach` loops into `in_array` when possible
```diff
-foreach ($items as $item) {
- if ($item === "something") {
2018-10-23 18:58:57 +00:00
- return true;
- }
-}
-
-return false;
+in_array("something", $items, true);
2018-10-23 18:58:57 +00:00
```
<br>
2018-12-31 11:50:32 +00:00
### `SimplifyForeachToArrayFilterRector`
- class: `Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToArrayFilterRector`
Simplify foreach with function filtering to array filter
```diff
-$directories = [];
$possibleDirectories = [];
-foreach ($possibleDirectories as $possibleDirectory) {
- if (file_exists($possibleDirectory)) {
- $directories[] = $possibleDirectory;
- }
-}
+$directories = array_filter($possibleDirectories, 'file_exists');
```
<br>
2018-10-21 22:26:45 +00:00
### `SimplifyForeachToCoalescingRector`
- class: `Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToCoalescingRector`
Changes foreach that returns set value to ??
```diff
-foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
- if ($currentFunction === $oldFunction) {
- return $newFunction;
- }
-}
-
-return null;
+return $this->oldToNewFunctions[$currentFunction] ?? null;
```
<br>
2018-10-21 22:26:45 +00:00
## CodeQuality\FuncCall
### `InArrayAndArrayKeysToArrayKeyExistsRector`
- class: `Rector\CodeQuality\Rector\FuncCall\InArrayAndArrayKeysToArrayKeyExistsRector`
Simplify `in_array` and `array_keys` functions combination into `array_key_exists` when `array_keys` has one argument only
```diff
-in_array("key", array_keys($array), true);
+array_key_exists("key", $array);
```
<br>
### `SimplifyInArrayValuesRector`
- class: `Rector\CodeQuality\Rector\FuncCall\SimplifyInArrayValuesRector`
Removes unneeded array_values() in in_array() call
```diff
-in_array("key", array_values($array), true);
+in_array("key", $array, true);
```
<br>
### `SimplifyFuncGetArgsCountRector`
- class: `Rector\CodeQuality\Rector\FuncCall\SimplifyFuncGetArgsCountRector`
Simplify count of func_get_args() to fun_num_args()
```diff
-count(func_get_args());
+func_num_args();
```
<br>
2018-12-31 11:50:32 +00:00
### `SingleInArrayToCompareRector`
- class: `Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector`
Changes in_array() with single element to ===
```diff
class SomeClass
{
public function run()
{
- if (in_array(strtolower($type), ['$this'], true)) {
+ if (strtolower($type) === '$this') {
return strtolower($type);
}
}
}
```
<br>
2018-10-23 18:58:57 +00:00
### `SimplifyStrposLowerRector`
2018-10-21 22:26:45 +00:00
2018-10-23 18:58:57 +00:00
- class: `Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector`
2018-10-21 22:26:45 +00:00
2018-10-23 18:58:57 +00:00
Simplify strpos(strtolower(), "...") calls
2018-10-21 22:26:45 +00:00
```diff
2018-10-23 18:58:57 +00:00
-strpos(strtolower($var), "...")"
+stripos($var, "...")"
2018-10-21 22:26:45 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
## CodeQuality\Identical
2018-10-21 22:26:45 +00:00
### `GetClassToInstanceOfRector`
- class: `Rector\CodeQuality\Rector\Identical\GetClassToInstanceOfRector`
Changes comparison with get_class to instanceof
2018-10-21 22:26:45 +00:00
```diff
-if (EventsListener::class === get_class($event->job)) { }
+if ($event->job instanceof EventsListener) { }
2018-10-21 22:26:45 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
### `SimplifyConditionsRector`
2018-10-21 22:26:45 +00:00
- class: `Rector\CodeQuality\Rector\Identical\SimplifyConditionsRector`
Simplify conditions
2018-10-21 22:26:45 +00:00
```diff
-if (! ($foo !== 'bar')) {...
+if ($foo === 'bar') {...
2018-10-21 22:26:45 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
### `SimplifyArraySearchRector`
2018-10-21 22:26:45 +00:00
- class: `Rector\CodeQuality\Rector\Identical\SimplifyArraySearchRector`
Simplify array_search to in_array
2018-10-21 22:26:45 +00:00
```diff
-array_search("searching", $array) !== false;
+in_array("searching", $array, true);
2018-10-21 22:26:45 +00:00
```
```diff
-array_search("searching", $array) != false;
+in_array("searching", $array);
```
2018-10-21 22:26:45 +00:00
<br>
2018-10-21 22:26:45 +00:00
## CodeQuality\If_
2018-10-21 22:26:45 +00:00
### `SimplifyIfNotNullReturnRector`
- class: `Rector\CodeQuality\Rector\If_\SimplifyIfNotNullReturnRector`
Changes redundant null check to instant return
2018-10-21 22:26:45 +00:00
```diff
$newNode = 'something ;
-if ($newNode !== null) {
- return $newNode;
-}
-
-return null;
+return $newNode;
2018-10-21 22:26:45 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
2018-12-31 11:50:32 +00:00
### `SimplifyIfElseToTernaryRector`
- class: `Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector`
Changes if/else for same value as assign to ternary
```diff
class SomeClass
{
public function run()
{
- if (empty($value)) {
- $this->arrayBuilt[][$key] = true;
- } else {
- $this->arrayBuilt[][$key] = $value;
- }
+ $this->arrayBuilt[][$key] = empty($value) ? true : $value;
}
}
```
<br>
### `SimplifyIfReturnBoolRector`
2018-10-21 22:26:45 +00:00
- class: `Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector`
Shortens if return false/true to direct return
2018-10-21 22:26:45 +00:00
```diff
-if (strpos($docToken->getContent(), "\n") === false) {
- return true;
-}
-
-return false;
+return strpos($docToken->getContent(), "\n") === false;
2018-10-21 22:26:45 +00:00
```
<br>
2018-10-23 18:58:57 +00:00
2019-01-22 20:34:38 +00:00
### `ConsecutiveNullCompareReturnsToNullCoalesceQueueRector`
- class: `Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector`
Change multiple null compares to ?? queue
```diff
class SomeClass
{
public function run()
{
- if (null !== $this->orderItem) {
- return $this->orderItem;
- }
-
- if (null !== $this->orderItemUnit) {
- return $this->orderItemUnit;
- }
-
- return null;
+ return $this->orderItem ?? $this->orderItemUnit;
}
}
```
<br>
## CodeQuality\LogicalOr
### `LogicalOrToBooleanOrRector`
- class: `Rector\CodeQuality\Rector\LogicalOr\LogicalOrToBooleanOrRector`
Change OR to || with more common understanding
```diff
-if ($f = false or true) {
+if (($f = false) || true) {
return $f;
}
```
<br>
## CodeQuality\Return_
2018-10-23 18:58:57 +00:00
### `SimplifyUselessVariableRector`
- class: `Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector`
Removes useless variable assigns
2018-10-23 18:58:57 +00:00
```diff
function () {
- $a = true;
- return $a;
+ return true;
};
2018-10-23 18:58:57 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
## CodeQuality\Ternary
### `TernaryToElvisRector`
- class: `Rector\CodeQuality\Rector\Ternary\TernaryToElvisRector`
Use ?: instead of ?, where useful
```diff
function elvis()
{
- $value = $a ? $a : false;
+ $value = $a ?: false;
}
```
<br>
2018-12-25 19:55:16 +00:00
### `SimplifyTautologyTernaryRector`
- class: `Rector\CodeQuality\Rector\Ternary\SimplifyTautologyTernaryRector`
Simplify tautology ternary to value
```diff
-$value = ($fullyQualifiedTypeHint !== $typeHint) ? $fullyQualifiedTypeHint : $typeHint;
+$value = $fullyQualifiedTypeHint;
```
<br>
### `UnnecessaryTernaryExpressionRector`
- class: `Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector`
Remove unnecessary ternary expressions.
```diff
-$foo === $bar ? true : false;
+$foo === $bar;
```
<br>
## CodingStyle\ClassConst
### `CompleteVarDocTypeConstantRector`
- class: `Rector\CodingStyle\Rector\ClassConst\CompleteVarDocTypeConstantRector`
Complete constant `@var` annotations for missing one, yet known.
```diff
final class SomeClass
{
+ /**
+ * @var int
+ */
private const NUMBER = 5;
}
```
<br>
## CodingStyle\ClassMethod
### `ReturnArrayClassMethodToYieldRector`
- class: `Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector`
Turns yield return to array return in specific type and method
```yaml
services:
Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector:
EventSubscriberInterface:
- getSubscribedEvents
```
```diff
class SomeEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
2019-01-03 12:47:44 +00:00
- yield 'event' => 'callback';
+ return ['event' => 'callback'];
}
}
```
<br>
### `YieldClassMethodToArrayClassMethodRector`
- class: `Rector\CodingStyle\Rector\ClassMethod\YieldClassMethodToArrayClassMethodRector`
Turns yield return to array return in specific type and method
```yaml
services:
Rector\CodingStyle\Rector\ClassMethod\YieldClassMethodToArrayClassMethodRector:
EventSubscriberInterface:
- getSubscribedEvents
```
```diff
class SomeEventSubscriber implements EventSubscriberInterface
2019-01-03 12:47:44 +00:00
{
public static function getSubscribedEvents()
{
2019-01-03 12:47:44 +00:00
- yield 'event' => 'callback';
+ return ['event' => 'callback'];
}
}
```
<br>
## CodingStyle\FuncCall
### `SetTypeToCastRector`
- class: `Rector\CodingStyle\Rector\FuncCall\SetTypeToCastRector`
Changes settype() to (type) where possible
```diff
class SomeClass
{
- public function run($foo)
+ public function run(array $items)
{
- settype($foo, 'string');
+ $foo = (string) $foo;
- return settype($foo, 'integer');
+ return (int) $foo;
}
}
```
<br>
### `ConsistentImplodeRector`
- class: `Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector`
Changes various implode forms to consistent one
```diff
class SomeClass
{
public function run(array $items)
{
- $itemsAsStrings = implode($items);
- $itemsAsStrings = implode($items, '|');
+ $itemsAsStrings = implode('', $items);
+ $itemsAsStrings = implode('|', $items);
$itemsAsStrings = implode('|', $items);
}
}
```
<br>
### `SimpleArrayCallableToStringRector`
- class: `Rector\CodingStyle\Rector\FuncCall\SimpleArrayCallableToStringRector`
Changes redundant anonymous bool functions to simple calls
```diff
-$paths = array_filter($paths, function ($path): bool {
- return is_dir($path);
-});
+array_filter($paths, "is_dir");
```
<br>
## CodingStyle\Identical
### `IdenticalFalseToBooleanNotRector`
- class: `Rector\CodingStyle\Rector\Identical\IdenticalFalseToBooleanNotRector`
Changes === false to negate !
```diff
-if ($something === false) {}
+if (! $something) {}
2018-10-21 22:26:45 +00:00
```
<br>
## CodingStyle\If_
### `NullableCompareToNullRector`
- class: `Rector\CodingStyle\Rector\If_\NullableCompareToNullRector`
Changes negate of empty comparison of nullable value to explicit === or !== compare
```diff
/** @var stdClass|null $value */
-if ($value) {
+if ($value !== null) {
}
-if (!$value) {
+if ($value === null) {
}
```
2018-10-21 22:26:45 +00:00
<br>
2018-10-21 22:26:45 +00:00
## CodingStyle\Switch_
### `BinarySwitchToIfElseRector`
- class: `Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector`
2018-10-21 22:26:45 +00:00
Changes switch with 2 options to if-else
```diff
-switch ($foo) {
- case 'my string':
- $result = 'ok';
- break;
-
- default:
- $result = 'not ok';
+if ($foo == 'my string') {
+ $result = 'ok;
+} else {
+ $result = 'not ok';
}
```
<br>
2018-10-21 22:26:45 +00:00
## CodingStyle\Use_
### `RemoveUnusedAliasRector`
- class: `Rector\CodingStyle\Rector\Use_\RemoveUnusedAliasRector`
Removes unused use aliases
```diff
-use Symfony\Kernel as BaseKernel;
+use Symfony\Kernel;
-class SomeClass extends BaseKernel
+class SomeClass extends Kernel
{
}
```
<br>
2018-12-25 19:55:16 +00:00
## DeadCode\Array_
### `RemoveDuplicatedArrayKeyRector`
- class: `Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector`
Remove duplicated key in defined arrays.
```diff
$item = [
1 => 'A',
- 1 => 'A'
];
```
<br>
## DeadCode\Assign
### `RemoveDoubleAssignRector`
- class: `Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector`
Simplify useless double assigns
```diff
-$value = 1;
$value = 1;
```
<br>
## DeadCode\ClassMethod
### `RemoveEmptyClassMethodRector`
- class: `Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector`
Remove empty method calls not required by parents
```diff
class OrphanClass
{
- public function __construct()
- {
- }
}
```
<br>
2018-12-31 11:50:32 +00:00
### `RemoveUnusedParameterRector`
- class: `Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector`
Remove unused parameter, if not required by interface or parent class
```diff
class SomeClass
{
- public function __construct($value, $value2)
+ public function __construct($value)
{
$this->value = $value;
}
}
```
<br>
## DeadCode\Expression
### `SimplifyMirrorAssignRector`
- class: `Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector`
Removes unneeded $a = $a assigns
```diff
-$a = $a;
```
<br>
2018-12-25 19:55:16 +00:00
## DeadCode\Foreach_
### `RemoveUnusedForeachKeyRector`
- class: `Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector`
Remove unused key in foreach
```diff
$items = [];
-foreach ($items as $key => $value) {
+foreach ($items as $value) {
$result = $value;
}
```
<br>
## DeadCode\Property
### `RemoveUnusedPrivatePropertyRector`
- class: `Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector`
Remove unused private properties
```diff
class SomeClass
{
- private $property;
}
```
<br>
## DeadCode\StaticCall
### `RemoveParentCallWithoutParentRector`
- class: `Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector`
Remove unused parent call with no parent class
```diff
class OrphanClass
{
public function __construct()
{
- parent::__construct();
}
}
```
<br>
## DeadCode\Stmt
### `RemoveDeadStmtRector`
- class: `Rector\DeadCode\Rector\Stmt\RemoveDeadStmtRector`
Removes dead code statements
```diff
-$value = 5;
-$value;
+$value = 5;
```
<br>
2018-08-01 20:09:34 +00:00
## Doctrine
### `AliasToClassRector`
- class: `Rector\Doctrine\Rector\AliasToClassRector`
Replaces doctrine alias with class.
```diff
2018-08-10 19:07:08 +00:00
$entityManager = new Doctrine\ORM\EntityManager();
-$entityManager->getRepository("AppBundle:Post");
+$entityManager->getRepository(\App\Entity\Post::class);
2018-08-01 20:09:34 +00:00
```
2018-07-31 21:47:59 +00:00
<br>
2018-12-14 19:35:35 +00:00
## DomainDrivenDesign\ObjectToScalar
2018-12-14 19:35:35 +00:00
### `ObjectToScalarDocBlockRector`
2018-12-14 19:35:35 +00:00
- class: `Rector\DomainDrivenDesign\Rector\ObjectToScalar\ObjectToScalarDocBlockRector`
2018-05-05 12:48:33 +00:00
2018-10-21 22:26:45 +00:00
Turns defined value object to simple types in doc blocks
```yaml
services:
2018-12-14 19:35:35 +00:00
Rector\DomainDrivenDesign\Rector\ObjectToScalar\ObjectToScalarDocBlockRector:
2018-10-21 22:26:45 +00:00
$valueObjectsToSimpleTypes:
ValueObject: string
```
2018-05-05 12:48:33 +00:00
```diff
2018-10-12 23:15:00 +00:00
/**
2018-10-21 22:26:45 +00:00
- * @var ValueObject|null
+ * @var string|null
2018-10-12 23:15:00 +00:00
*/
2018-10-21 22:26:45 +00:00
private $name;
2018-10-21 22:26:45 +00:00
-/** @var ValueObject|null */
+/** @var string|null */
$name;
```
<br>
2018-12-14 19:35:35 +00:00
### `ObjectToScalarRector`
2018-10-21 22:26:45 +00:00
2018-12-14 19:35:35 +00:00
- class: `Rector\DomainDrivenDesign\Rector\ObjectToScalar\ObjectToScalarRector`
2018-10-21 22:26:45 +00:00
Remove values objects and use directly the value.
```yaml
services:
2018-12-14 19:35:35 +00:00
Rector\DomainDrivenDesign\Rector\ObjectToScalar\ObjectToScalarRector:
2018-10-21 22:26:45 +00:00
$valueObjectsToSimpleTypes:
ValueObject: string
```
2018-07-31 12:50:39 +00:00
```diff
2018-10-21 22:26:45 +00:00
-$name = new ValueObject("name");
+$name = "name";
2018-10-12 23:15:00 +00:00
2018-12-14 19:35:35 +00:00
-function someFunction(ValueObject $name): ?ValueObject {
+function someFunction(string $name): ?string {
}
2018-07-31 12:50:39 +00:00
```
<br>
## Guzzle\MethodCall
### `MessageAsArrayRector`
- class: `Rector\Guzzle\Rector\MethodCall\MessageAsArrayRector`
Changes getMessage(..., true) to getMessageAsArray()
```diff
/** @var GuzzleHttp\Message\MessageInterface */
-$value = $message->getMessage('key', true);
+$value = $message->getMessageAsArray('key');
```
<br>
2018-10-21 22:26:45 +00:00
## Jms\Property
2018-09-28 16:33:35 +00:00
2018-10-21 22:26:45 +00:00
### `JmsInjectAnnotationRector`
2018-09-28 16:33:35 +00:00
2018-10-21 22:26:45 +00:00
- class: `Rector\Jms\Rector\Property\JmsInjectAnnotationRector`
Changes properties with `@JMS\DiExtraBundle\Annotation\Inject` to constructor injection
2018-09-28 16:33:35 +00:00
```diff
2018-10-21 22:26:45 +00:00
use JMS\DiExtraBundle\Annotation as DI;
class SomeController
{
/**
- * @DI\Inject("entity.manager")
+ * @var EntityManager
*/
private $entityManager;
+
+ public function __construct(EntityManager $entityManager)
+ {
+ $this->entityManager = entityManager;
+ }
}
2018-09-28 16:33:35 +00:00
```
<br>
2019-02-02 16:22:15 +00:00
## NetteToSymfony
### `RouterListToControllerAnnotationsRector`
- class: `Rector\NetteToSymfony\Rector\RouterListToControllerAnnotationsRector`
Change new Route() from RouteFactory to @Route annotation above controller method
```diff
final class RouterFactory
{
public function create(): RouteList
{
$routeList = new RouteList();
+
+ // case of single action controller, usually get() or __invoke() method
$routeList[] = new Route('some-path', SomePresenter::class);
return $routeList;
}
}
final class SomePresenter
{
+ /**
+ * @Symfony\Component\Routing\Annotation\Route(path="some-path")
+ */
public function run()
{
}
}
```
<br>
## PHPStan\Assign
### `PHPStormVarAnnotationRector`
- class: `Rector\PHPStan\Rector\Assign\PHPStormVarAnnotationRector`
Change various @var annotation formats to one PHPStorm understands
```diff
-$config = 5;
-/** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */
+/** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */
+$config = 5;
```
<br>
## PHPStan\Cast
### `RecastingRemovalRector`
- class: `Rector\PHPStan\Rector\Cast\RecastingRemovalRector`
Removes recasting of the same type
```diff
$string = '';
-$string = (string) $string;
+$string = $string;
$array = [];
-$array = (array) $array;
+$array = $array;
```
<br>
2018-10-21 22:26:45 +00:00
## PHPUnit
### `ExceptionAnnotationRector`
- class: `Rector\PHPUnit\Rector\ExceptionAnnotationRector`
2018-07-31 12:50:39 +00:00
Takes `setExpectedException()` 2nd and next arguments to own methods in PHPUnit.
2018-07-31 12:50:39 +00:00
```diff
-/**
- * @expectedException Exception
- * @expectedExceptionMessage Message
- */
public function test()
2018-10-12 23:15:00 +00:00
{
+ $this->expectException('Exception');
+ $this->expectExceptionMessage('Message');
// tested code
2018-10-12 23:15:00 +00:00
}
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
<br>
2018-10-21 22:26:45 +00:00
### `DelegateExceptionArgumentsRector`
- class: `Rector\PHPUnit\Rector\DelegateExceptionArgumentsRector`
Takes `setExpectedException()` 2nd and next arguments to own methods in PHPUnit.
```diff
-$this->setExpectedException(Exception::class, "Message", "CODE");
+$this->setExpectedException(Exception::class);
+$this->expectExceptionMessage("Message");
+$this->expectExceptionCode("CODE");
```
<br>
2018-10-21 22:26:45 +00:00
### `TryCatchToExpectExceptionRector`
- class: `Rector\PHPUnit\Rector\TryCatchToExpectExceptionRector`
Turns try/catch to expectException() call
```diff
-try {
- $someService->run();
-} catch (Throwable $exception) {
- $this->assertInstanceOf(RuntimeException::class, $e);
- $this->assertContains('There was an error executing the following script', $e->getMessage());
-}
+$this->expectException(RuntimeException::class);
+$this->expectExceptionMessage('There was an error executing the following script');
+$someService->run();
```
<br>
2018-10-12 23:15:00 +00:00
### `GetMockRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\PHPUnit\Rector\GetMockRector`
Turns getMock*() methods to createMock()
2018-10-12 23:15:00 +00:00
2018-08-01 20:09:34 +00:00
```diff
-$this->getMock("Class");
+$this->createMock("Class");
```
```diff
-$this->getMockWithoutInvokingTheOriginalConstructor("Class");
+$this->createMock("Class");
2018-07-31 12:50:39 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
## PHPUnit\Foreach_
### `SimplifyForeachInstanceOfRector`
- class: `Rector\PHPUnit\Rector\Foreach_\SimplifyForeachInstanceOfRector`
Simplify unnecessary foreach check of instances
2018-10-12 23:15:00 +00:00
```diff
2018-10-21 22:26:45 +00:00
-foreach ($foos as $foo) {
- $this->assertInstanceOf(\SplFileInfo::class, $foo);
-}
+$this->assertContainsOnlyInstancesOf(\SplFileInfo::class, $foos);
2018-10-12 23:15:00 +00:00
```
<br>
2018-10-23 18:58:57 +00:00
2018-12-14 19:35:35 +00:00
## PHPUnit\MethodCall
### `AssertEqualsParameterToSpecificMethodsTypeRector`
- class: `Rector\PHPUnit\Rector\MethodCall\AssertEqualsParameterToSpecificMethodsTypeRector`
Change assertEquals()/assertNotEquals() method parameters to new specific alternatives
```diff
final class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
$value = 'value';
- $this->assertEquals('string', $value, 'message', 5.0);
+ $this->assertEqualsWithDelta('string', $value, 5.0, 'message');
- $this->assertEquals('string', $value, 'message', 0.0, 20);
+ $this->assertEquals('string', $value, 'message', 0.0);
- $this->assertEquals('string', $value, 'message', 0.0, 10, true);
+ $this->assertEqualsCanonicalizing('string', $value, 'message');
- $this->assertEquals('string', $value, 'message', 0.0, 10, false, true);
+ $this->assertEqualsIgnoringCase('string', $value, 'message');
}
}
```
<br>
### `SpecificAssertContainsRector`
- class: `Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsRector`
Change assertContains()/assertNotContains() method to new string and iterable alternatives
```diff
<?php
final class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
- $this->assertContains('foo', 'foo bar');
- $this->assertNotContains('foo', 'foo bar');
- $this->assertContains('foo', ['foo', 'bar']);
- $this->assertNotContains('foo', ['foo', 'bar']);
+ $this->assertStringContains('foo', 'foo bar');
+ $this->assertStringNotContains('foo', 'foo bar');
+ $this->assertIterableContains('foo', ['foo', 'bar']);
+ $this->assertIterableNotContains('foo', ['foo', 'bar']);
}
}
```
<br>
### `UseSpecificWillMethodRector`
- class: `Rector\PHPUnit\Rector\MethodCall\UseSpecificWillMethodRector`
Changes ->will($this->xxx()) to one specific method
```diff
class SomeClass extends PHPUnit\Framework\TestCase
{
public function test()
{
$translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
$translator->expects($this->any())
->method('trans')
- ->with($this->equalTo('old max {{ max }}!'))
- ->will($this->returnValue('translated max {{ max }}!'));
+ ->with('old max {{ max }}!')
+ ->willReturnValue('translated max {{ max }}!');
}
}
```
<br>
2018-12-14 19:35:35 +00:00
### `SpecificAssertInternalTypeRector`
- class: `Rector\PHPUnit\Rector\MethodCall\SpecificAssertInternalTypeRector`
Change assertInternalType()/assertNotInternalType() method to new specific alternatives
```diff
final class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
$value = 'value';
- $this->assertInternalType('string', $value);
- $this->assertNotInternalType('array', $value);
+ $this->assertIsString($value);
+ $this->assertIsNotArray($value);
}
}
```
<br>
## PHPUnit\SpecificMethod
2018-10-23 18:58:57 +00:00
### `AssertNotOperatorRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertNotOperatorRector`
Turns not-operator comparisons to their method name alternatives in PHPUnit TestCase
2018-07-31 12:50:39 +00:00
```diff
-$this->assertTrue(!$foo, "message");
+$this->assertFalse($foo, "message");
2018-08-01 20:09:34 +00:00
```
2018-08-01 20:09:34 +00:00
```diff
-$this->assertFalse(!$foo, "message");
+$this->assertTrue($foo, "message");
2018-07-31 12:50:39 +00:00
```
<br>
### `AssertComparisonToSpecificMethodRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertComparisonToSpecificMethodRector`
2018-07-31 12:50:39 +00:00
Turns comparison operations to their method name alternatives in PHPUnit TestCase
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
```diff
-$this->assertTrue($foo === $bar, "message");
+$this->assertSame($bar, $foo, "message");
2018-10-12 23:15:00 +00:00
```
```diff
-$this->assertFalse($foo >= $bar, "message");
+$this->assertLessThanOrEqual($bar, $foo, "message");
2018-10-12 23:15:00 +00:00
```
<br>
2018-07-31 12:50:39 +00:00
2018-10-23 18:58:57 +00:00
### `AssertPropertyExistsRector`
2018-10-23 18:58:57 +00:00
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertPropertyExistsRector`
2018-07-31 12:50:39 +00:00
2018-10-23 18:58:57 +00:00
Turns `property_exists` comparisons to their method name alternatives in PHPUnit TestCase
2018-07-31 12:50:39 +00:00
```diff
2018-10-23 18:58:57 +00:00
-$this->assertTrue(property_exists(new Class, "property"), "message");
+$this->assertClassHasAttribute("property", "Class", "message");
2018-08-01 20:09:34 +00:00
```
2018-08-01 20:09:34 +00:00
```diff
2018-10-23 18:58:57 +00:00
-$this->assertFalse(property_exists(new Class, "property"), "message");
+$this->assertClassNotHasAttribute("property", "Class", "message");
2018-07-31 12:50:39 +00:00
```
<br>
### `AssertTrueFalseInternalTypeToSpecificMethodRector`
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertTrueFalseInternalTypeToSpecificMethodRector`
Turns true/false with internal type comparisons to their method name alternatives in PHPUnit TestCase
```diff
-$this->assertTrue(is_{internal_type}($anything), "message");
+$this->assertInternalType({internal_type}, $anything, "message");
```
```diff
-$this->assertFalse(is_{internal_type}($anything), "message");
+$this->assertNotInternalType({internal_type}, $anything, "message");
```
<br>
2018-10-12 23:15:00 +00:00
### `AssertIssetToSpecificMethodRector`
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertIssetToSpecificMethodRector`
Turns isset comparisons to their method name alternatives in PHPUnit TestCase
```diff
-$this->assertTrue(isset($anything->foo));
+$this->assertFalse(isset($anything["foo"]), "message");
```
```diff
-$this->assertObjectHasAttribute("foo", $anything);
+$this->assertArrayNotHasKey("foo", $anything, "message");
```
<br>
2018-10-12 23:15:00 +00:00
### `AssertFalseStrposToContainsRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertFalseStrposToContainsRector`
Turns `strpos`/`stripos` comparisons to their method name alternatives in PHPUnit TestCase
2018-10-12 23:15:00 +00:00
2018-10-21 22:26:45 +00:00
```diff
-$this->assertFalse(strpos($anything, "foo"), "message");
+$this->assertNotContains("foo", $anything, "message");
2018-10-21 22:26:45 +00:00
```
2018-10-12 23:15:00 +00:00
```diff
-$this->assertNotFalse(stripos($anything, "foo"), "message");
+$this->assertContains("foo", $anything, "message");
```
2018-10-12 23:15:00 +00:00
<br>
2018-10-21 22:26:45 +00:00
### `AssertSameBoolNullToSpecificMethodRector`
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertSameBoolNullToSpecificMethodRector`
Turns same bool and null comparisons to their method name alternatives in PHPUnit TestCase
2018-10-12 23:15:00 +00:00
```diff
-$this->assertSame(null, $anything);
+$this->assertNull($anything);
2018-10-12 23:15:00 +00:00
```
```diff
-$this->assertNotSame(false, $anything);
+$this->assertNotFalse($anything);
2018-10-12 23:15:00 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
### `AssertCompareToSpecificMethodRector`
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertCompareToSpecificMethodRector`
Turns vague php-only method in PHPUnit TestCase to more specific
```diff
-$this->assertSame(10, count($anything), "message");
+$this->assertCount(10, $anything, "message");
```
```diff
-$this->assertSame($value, {function}($anything), "message");
+$this->assert{function}($value, $anything, "message\");
```
```diff
-$this->assertEquals($value, {function}($anything), "message");
+$this->assert{function}($value, $anything, "message\");
```
```diff
-$this->assertNotSame($value, {function}($anything), "message");
+$this->assertNot{function}($value, $anything, "message")
```
```diff
-$this->assertNotEquals($value, {function}($anything), "message");
+$this->assertNot{function}($value, $anything, "message")
```
<br>
2018-10-12 23:15:00 +00:00
### `AssertRegExpRector`
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertRegExpRector`
Turns `preg_match` comparisons to their method name alternatives in PHPUnit TestCase
```diff
-$this->assertSame(1, preg_match("/^Message for ".*"\.$/", $string), $message);
+$this->assertRegExp("/^Message for ".*"\.$/", $string, $message);
```
```diff
-$this->assertEquals(false, preg_match("/^Message for ".*"\.$/", $string), $message);
+$this->assertNotRegExp("/^Message for ".*"\.$/", $string, $message);
```
<br>
2018-10-12 23:15:00 +00:00
### `AssertInstanceOfComparisonRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertInstanceOfComparisonRector`
Turns instanceof comparisons to their method name alternatives in PHPUnit TestCase
2018-10-12 23:15:00 +00:00
```diff
-$this->assertTrue($foo instanceof Foo, "message");
+$this->assertFalse($foo instanceof Foo, "message");
2018-10-12 23:15:00 +00:00
```
```diff
-$this->assertInstanceOf("Foo", $foo, "message");
+$this->assertNotInstanceOf("Foo", $foo, "message");
```
<br>
### `AssertTrueFalseToSpecificMethodRector`
- class: `Rector\PHPUnit\Rector\SpecificMethod\AssertTrueFalseToSpecificMethodRector`
Turns true/false comparisons to their method name alternatives in PHPUnit TestCase when possible
```diff
-$this->assertTrue(is_readable($readmeFile), "message");
+$this->assertIsReadable($readmeFile, "message");
2018-10-12 23:15:00 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
## PhpParser
### `RemoveNodeRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\PhpParser\Rector\RemoveNodeRector`
2018-10-12 23:15:00 +00:00
Turns integer return to remove node to constant in NodeVisitor of PHP-Parser
2018-10-12 23:15:00 +00:00
```diff
public function leaveNode()
{
- return false;
+ return NodeTraverser::REMOVE_NODE;
}
2018-10-12 23:15:00 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
### `ParamAndStaticVarNameRector`
- class: `Rector\PhpParser\Rector\ParamAndStaticVarNameRector`
Turns old string `var` to `var->name` sub-variable in Node of PHP-Parser
```diff
-$paramNode->name;
+$paramNode->var->name;
```
```diff
-$staticVarNode->name;
+$staticVarNode->var->name;
```
<br>
2018-10-21 22:26:45 +00:00
### `IdentifierRector`
2018-10-21 22:26:45 +00:00
- class: `Rector\PhpParser\Rector\IdentifierRector`
Turns node string names to Identifier object in php-parser
2018-10-21 22:26:45 +00:00
```diff
$constNode = new PhpParser\Node\Const_;
-$name = $constNode->name;
+$name = $constNode->name->toString();'
2018-10-12 23:15:00 +00:00
```
<br>
### `CatchAndClosureUseNameRector`
- class: `Rector\PhpParser\Rector\CatchAndClosureUseNameRector`
Turns `$catchNode->var` to its new `name` property in php-parser
```diff
-$catchNode->var;
+$catchNode->var->name
```
<br>
2018-10-12 23:15:00 +00:00
### `SetLineRector`
- class: `Rector\PhpParser\Rector\SetLineRector`
Turns standalone line method to attribute in Node of PHP-Parser
```diff
-$node->setLine(5);
+$node->setAttribute("line", 5);
```
<br>
2018-10-12 23:15:00 +00:00
### `UseWithAliasRector`
- class: `Rector\PhpParser\Rector\UseWithAliasRector`
Turns use property to method and `$node->alias` to last name in UseAlias Node of PHP-Parser
```diff
-$node->alias;
+$node->getAlias();
```
```diff
-$node->name->getLast();
+$node->alias
```
<br>
2018-10-23 18:58:57 +00:00
2018-10-12 23:15:00 +00:00
## Php\Assign
### `AssignArrayToStringRector`
- class: `Rector\Php\Rector\Assign\AssignArrayToStringRector`
String cannot be turned into array by assignment anymore
```diff
-$string = '';
+$string = [];
$string[] = 1;
```
<br>
2019-01-22 20:34:38 +00:00
### `NullCoalescingOperatorRector`
- class: `Rector\Php\Rector\Assign\NullCoalescingOperatorRector`
Use null coalescing operator ??=
```diff
$array = [];
-$array['user_id'] = $array['user_id'] ?? 'value';
+$array['user_id'] ??= 'value';
```
<br>
2018-12-14 19:35:35 +00:00
### `MysqlAssignToMysqliRector`
- class: `Rector\Php\Rector\Assign\MysqlAssignToMysqliRector`
Converts more complex mysql functions to mysqli
```diff
-$data = mysql_db_name($result, $row);
+mysqli_data_seek($result, $row);
+$fetch = mysql_fetch_row($result);
+$data = $fetch[0];
```
<br>
2018-10-12 23:15:00 +00:00
## Php\BinaryOp
### `IsCountableRector`
- class: `Rector\Php\Rector\BinaryOp\IsCountableRector`
Changes is_array + Countable check to is_countable
```diff
-is_array($foo) || $foo instanceof Countable;
+is_countable($foo);
```
<br>
2018-10-12 23:15:00 +00:00
### `IsIterableRector`
- class: `Rector\Php\Rector\BinaryOp\IsIterableRector`
Changes is_array + Traversable check to is_iterable
```diff
-is_array($foo) || $foo instanceof Traversable;
+is_iterable($foo);
```
<br>
2018-10-12 23:15:00 +00:00
## Php\ClassConst
### `PublicConstantVisibilityRector`
- class: `Rector\Php\Rector\ClassConst\PublicConstantVisibilityRector`
Add explicit public constant visibility.
```diff
class SomeClass
{
- const HEY = 'you';
+ public const HEY = 'you';
}
```
<br>
2018-10-12 23:15:00 +00:00
## Php\ConstFetch
2018-10-12 23:15:00 +00:00
### `SensitiveConstantNameRector`
2018-07-31 12:50:39 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\ConstFetch\SensitiveConstantNameRector`
2018-07-31 12:50:39 +00:00
2018-10-12 23:15:00 +00:00
Changes case insensitive constants to sensitive ones.
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
define('FOO', 42, true);
var_dump(FOO);
-var_dump(foo);
+var_dump(FOO);
2018-07-31 12:50:39 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
### `BarewordStringRector`
- class: `Rector\Php\Rector\ConstFetch\BarewordStringRector`
Changes unquoted non-existing constants to strings
```diff
-var_dump(VAR);
2018-12-31 19:29:12 +00:00
+var_dump("VAR");
2018-10-21 22:26:45 +00:00
```
<br>
2019-01-22 20:34:38 +00:00
## Php\Double
### `RealToFloatTypeCastRector`
- class: `Rector\Php\Rector\Double\RealToFloatTypeCastRector`
Change deprecated (real) to (float)
```diff
class SomeClass
{
public function run()
{
- $number = (real) 5;
+ $number = (float) 5;
$number = (float) 5;
$number = (double) 5;
}
}
```
<br>
2018-10-12 23:15:00 +00:00
## Php\Each
2018-10-12 23:15:00 +00:00
### `WhileEachToForeachRector`
2018-07-31 12:50:39 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\Each\WhileEachToForeachRector`
each() function is deprecated, use foreach() instead.
2018-07-31 12:50:39 +00:00
```diff
2018-10-12 23:15:00 +00:00
-while (list($key, $callback) = each($callbacks)) {
+foreach ($callbacks as $key => $callback) {
// ...
}
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-while (list($key) = each($callbacks)) {
+foreach (array_keys($callbacks) as $key) {
// ...
}
2018-07-31 12:50:39 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
### `ListEachRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\Each\ListEachRector`
2018-07-31 12:50:39 +00:00
2018-10-12 23:15:00 +00:00
each() function is deprecated, use foreach() instead.
2018-07-31 12:50:39 +00:00
```diff
2018-10-12 23:15:00 +00:00
-list($key, $callback) = each($callbacks);
+$key = key($opt->option);
+$val = current($opt->option);
2018-08-01 20:09:34 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
## Php\FuncCall
### `CreateFunctionToAnonymousFunctionRector`
- class: `Rector\Php\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector`
Use anonymous functions instead of deprecated create_function()
```diff
class ClassWithCreateFunction
{
public function run()
{
- $callable = create_function('$matches', "return '$delimiter' . strtolower(\$matches[1]);");
+ $callable = function($matches) use ($delimiter) {
+ return $delimiter . strtolower($matches[1]);
+ };
}
}
```
<br>
### `RandomFunctionRector`
- class: `Rector\Php\Rector\FuncCall\RandomFunctionRector`
Changes rand, srand and getrandmax by new md_* alternatives.
```diff
-rand();
+mt_rand();
```
<br>
2018-12-31 11:50:32 +00:00
### `FilterVarToAddSlashesRector`
- class: `Rector\Php\Rector\FuncCall\FilterVarToAddSlashesRector`
Change filter_var() with slash escaping to addslashes()
```diff
$var= "Satya's here!";
-filter_var($var, FILTER_SANITIZE_MAGIC_QUOTES);
+addslashes($var);
```
<br>
### `GetClassOnNullRector`
- class: `Rector\Php\Rector\FuncCall\GetClassOnNullRector`
Null is no more allowed in get_class()
```diff
final class SomeClass
{
public function getItem()
{
$value = null;
- return get_class($value);
+ return $value !== null ? get_class($value) : self::class;
}
}
```
<br>
2018-12-31 11:50:32 +00:00
### `ArrayKeyExistsOnPropertyRector`
- class: `Rector\Php\Rector\FuncCall\ArrayKeyExistsOnPropertyRector`
Change array_key_exists() on property to property_exists()
```diff
class SomeClass {
public $value;
}
$someClass = new SomeClass;
-array_key_exists('value', $someClass);
+property_exists($someClass, 'value');
```
<br>
### `ArrayKeyFirstLastRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\Php\Rector\FuncCall\ArrayKeyFirstLastRector`
Make use of array_key_first() and array_key_last()
2018-07-31 12:50:39 +00:00
```diff
-reset($items);
-$firstKey = key($items);
+$firstKey = array_key_first($items);
2018-08-01 20:09:34 +00:00
```
2018-08-01 20:09:34 +00:00
```diff
-end($items);
-$lastKey = key($items);
+$lastKey = array_key_last($items);
2018-07-31 12:50:39 +00:00
```
<br>
### `CallUserMethodRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\Php\Rector\FuncCall\CallUserMethodRector`
2018-07-31 12:50:39 +00:00
Changes call_user_method()/call_user_method_array() to call_user_func()/call_user_func_array()
```diff
-call_user_method($method, $obj, "arg1", "arg2");
+call_user_func(array(&$obj, "method"), "arg1", "arg2");
2018-10-21 22:26:45 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
### `StringifyStrNeedlesRector`
2018-10-21 22:26:45 +00:00
- class: `Rector\Php\Rector\FuncCall\StringifyStrNeedlesRector`
2018-10-21 22:26:45 +00:00
Makes needles explicit strings
2018-10-21 22:26:45 +00:00
2018-10-23 18:58:57 +00:00
```diff
$needle = 5;
-$fivePosition = strpos('725', $needle);
+$fivePosition = strpos('725', (string) $needle);
2018-10-23 18:58:57 +00:00
```
2018-10-21 22:26:45 +00:00
<br>
2018-10-21 22:26:45 +00:00
### `StringsAssertNakedRector`
- class: `Rector\Php\Rector\FuncCall\StringsAssertNakedRector`
String asserts must be passed directly to assert()
```diff
function nakedAssert()
{
- assert('true === true');
- assert("true === true");
+ assert(true === true);
+ assert(true === true);
}
```
<br>
### `ParseStrWithResultArgumentRector`
- class: `Rector\Php\Rector\FuncCall\ParseStrWithResultArgumentRector`
Use $result argument in parse_str() function
```diff
-parse_str($this->query);
-$data = get_defined_vars();
+parse_str($this->query, $result);
+$data = $result;
```
<br>
### `IsObjectOnIncompleteClassRector`
- class: `Rector\Php\Rector\FuncCall\IsObjectOnIncompleteClassRector`
Incomplete class returns inverted bool on is_object()
```diff
$incompleteObject = new __PHP_Incomplete_Class;
-$isObject = is_object($incompleteObject);
+$isObject = ! is_object($incompleteObject);
```
<br>
### `RemoveExtraParametersRector`
- class: `Rector\Php\Rector\FuncCall\RemoveExtraParametersRector`
Remove extra parameters
```diff
-strlen("asdf", 1);
+strlen("asdf");
```
<br>
2018-12-31 11:50:32 +00:00
### `GetCalledClassToStaticClassRector`
- class: `Rector\Php\Rector\FuncCall\GetCalledClassToStaticClassRector`
Change __CLASS__ to self::class
```diff
class SomeClass
-{
- public function callOnMe()
- {
- var_dump( get_called_class());
- }
-}
+ {
+ public function callOnMe()
+ {
+ var_dump( static::class);
+ }
+ }
```
<br>
2018-12-14 19:35:35 +00:00
### `MysqlFuncCallToMysqliRector`
- class: `Rector\Php\Rector\FuncCall\MysqlFuncCallToMysqliRector`
Converts more complex mysql functions to mysqli
```diff
-mysql_drop_db($database);
+mysqli_query('DROP DATABASE ' . $database);
```
<br>
### `CountOnNullRector`
2018-10-23 18:58:57 +00:00
- class: `Rector\Php\Rector\FuncCall\CountOnNullRector`
Changes count() on null to safe ternary check
2018-10-21 22:26:45 +00:00
```diff
$values = null;
-$count = count($values);
+$count = is_array($values) || $values instanceof Countable ? count($values) : 0;
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
<br>
2018-10-12 23:15:00 +00:00
### `SensitiveDefineRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\FuncCall\SensitiveDefineRector`
2018-07-31 12:50:39 +00:00
2018-10-12 23:15:00 +00:00
Changes case insensitive constants to sensitive ones.
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-define('FOO', 42, true);
+define('FOO', 42);
2018-07-31 12:50:39 +00:00
```
<br>
### `RegexDashEscapeRector`
- class: `Rector\Php\Rector\FuncCall\RegexDashEscapeRector`
Escape - in some cases
```diff
-preg_match("#[\w-()]#", 'some text');
+preg_match("#[\w\-()]#", 'some text');
```
<br>
2018-10-12 23:15:00 +00:00
### `MultiDirnameRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\FuncCall\MultiDirnameRector`
2018-07-31 12:50:39 +00:00
2018-10-12 23:15:00 +00:00
Changes multiple dirname() calls to one with nesting level
2018-07-31 12:50:39 +00:00
```diff
2018-10-12 23:15:00 +00:00
-dirname(dirname($path));
+dirname($path, 2);
2018-08-01 20:09:34 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
### `JsonThrowOnErrorRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\FuncCall\JsonThrowOnErrorRector`
Adds JSON_THROW_ON_ERROR to json_encode() and json_decode() to throw JsonException on error
2018-10-12 23:15:00 +00:00
2018-08-01 20:09:34 +00:00
```diff
-json_encode($content);
-json_decode($json);
+json_encode($content, JSON_THROW_ON_ERROR
+json_decode($json, null, null, JSON_THROW_ON_ERROR););
2018-07-31 12:50:39 +00:00
```
<br>
### `EregToPregMatchRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\Php\Rector\FuncCall\EregToPregMatchRector`
Changes ereg*() to preg*() calls
2018-07-31 12:50:39 +00:00
```diff
-ereg("hi")
+preg_match("#hi#");
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
<br>
2018-10-12 23:15:00 +00:00
2018-12-31 11:50:32 +00:00
### `MbStrrposEncodingArgumentPositionRector`
- class: `Rector\Php\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector`
Change mb_strrpos() encoding argument position
```diff
-mb_strrpos($text, "abc", "UTF-8");
+mb_strrpos($text, "abc", 0, "UTF-8");
```
<br>
### `PowToExpRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\FuncCall\PowToExpRector`
Changes pow(val, val2) to ** (exp) parameter
2018-10-12 23:15:00 +00:00
2018-08-01 20:09:34 +00:00
```diff
-pow(1, 2);
+1**2;
2018-05-05 12:48:33 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
## Php\FunctionLike
2018-10-12 23:15:00 +00:00
### `ExceptionHandlerTypehintRector`
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\FunctionLike\ExceptionHandlerTypehintRector`
Changes property `@var` annotations from annotation to type.
```diff
2018-10-12 23:15:00 +00:00
-function handler(Exception $exception) { ... }
+function handler(Throwable $exception) { ... }
set_exception_handler('handler');
```
<br>
### `ReturnTypeDeclarationRector`
- class: `Rector\Php\Rector\FunctionLike\ReturnTypeDeclarationRector`
2019-01-08 17:55:51 +00:00
Change @return types and type from static analysis to type declarations if not a BC-break
```diff
<?php
class SomeClass
{
/**
* @return int
*/
- public function getCount()
+ public function getCount(): int
{
}
}
```
<br>
### `ParamTypeDeclarationRector`
- class: `Rector\Php\Rector\FunctionLike\ParamTypeDeclarationRector`
2019-01-08 17:55:51 +00:00
Change @param types to type declarations if not a BC-break
```diff
<?php
class ParentClass
{
/**
* @param int $number
*/
public function keep($number)
{
}
}
final class ChildClass extends ParentClass
{
/**
* @param int $number
*/
public function keep($number)
{
}
/**
* @param int $number
*/
- public function change($number)
+ public function change(int $number)
{
}
}
```
<br>
2018-10-12 23:15:00 +00:00
### `Php4ConstructorRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\FunctionLike\Php4ConstructorRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
Changes PHP 4 style constructor to __construct.
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
class SomeClass
2018-08-01 20:09:34 +00:00
{
2018-10-12 23:15:00 +00:00
- public function SomeClass()
+ public function __construct()
{
}
2018-08-01 20:09:34 +00:00
}
```
<br>
2018-12-31 19:29:12 +00:00
## Php\If_
### `IfToSpaceshipRector`
- class: `Rector\Php\Rector\If_\IfToSpaceshipRector`
Changes if/else to spaceship <=> where useful
```diff
class SomeClass
{
public function run()
{
usort($languages, function ($a, $b) {
- if ($a[0] === $b[0]) {
- return 0;
- }
-
- return ($a[0] < $b[0]) ? 1 : -1;
+ return $b[0] <=> $a[0];
});
}
}
```
<br>
2018-10-12 23:15:00 +00:00
## Php\List_
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
### `ListSplitStringRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\List_\ListSplitStringRector`
list() cannot split string directly anymore, use str_split()
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-list($foo) = "string";
+list($foo) = str_split("string");
2018-08-01 20:09:34 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
### `EmptyListRector`
- class: `Rector\Php\Rector\List_\EmptyListRector`
list() cannot be empty
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-list() = $values;
+list($generated) = $values;
2018-08-01 20:09:34 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
### `ListSwapArrayOrderRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\List_\ListSwapArrayOrderRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
list() assigns variables in reverse order - relevant in array assign
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-list($a[], $a[]) = [1, 2];
+list($a[], $a[]) = array_reverse([1, 2])];
2018-08-01 20:09:34 +00:00
```
<br>
2018-12-31 11:50:32 +00:00
## Php\MagicConstClass
### `ClassConstantToSelfClassRector`
- class: `Rector\Php\Rector\MagicConstClass\ClassConstantToSelfClassRector`
Change __CLASS__ to self::class
```diff
class SomeClass
{
public function callOnMe()
{
- var_dump(__CLASS__);
+ var_dump(self::class);
}
}
```
<br>
2018-12-31 19:29:12 +00:00
## Php\MethodCall
### `ThisCallOnStaticMethodToStaticCallRector`
- class: `Rector\Php\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector`
Changes $this->call() to static method to static call
```diff
class SomeClass
{
public static function run()
{
- $this->eat();
+ self::eat();
}
public static function eat()
{
}
}
```
<br>
### `PreferThisOrSelfMethodCallRector`
- class: `Rector\Php\Rector\MethodCall\PreferThisOrSelfMethodCallRector`
Changes $this->... to self:: or vise versa for specific types
```yaml
services:
Rector\Php\Rector\MethodCall\PreferThisOrSelfMethodCallRector:
PHPUnit\TestCase: self
```
```diff
class SomeClass extends PHPUnit\TestCase
{
public function run()
{
- $this->assertThis();
+ self::assertThis();
}
}
```
<br>
2018-10-12 23:15:00 +00:00
## Php\Name
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
### `ReservedObjectRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\Name\ReservedObjectRector`
Changes reserved "Object" name to "<Smart>Object" where <Smart> can be configured
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-class Object
+class SmartObject
{
}
2018-08-01 20:09:34 +00:00
```
<br>
2018-10-12 23:15:00 +00:00
## Php\Property
2018-08-01 20:09:34 +00:00
### `CompleteVarDocTypePropertyRector`
- class: `Rector\Php\Rector\Property\CompleteVarDocTypePropertyRector`
Complete property `@var` annotations for missing one, yet known.
```diff
final class SomeClass
{
+ /**
+ * @var EventDispatcher
+ */
private $eventDispatcher;
public function __construct(EventDispatcher $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
}
```
<br>
2018-10-12 23:15:00 +00:00
### `TypedPropertyRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\Property\TypedPropertyRector`
Changes property `@var` annotations from annotation to type.
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
final class SomeClass
{
- /**
- * @var int
- */
- private count;
+ private int count;
}
2018-08-01 20:09:34 +00:00
```
<br>
2018-12-31 11:50:32 +00:00
## Php\StaticCall
2018-12-31 19:29:12 +00:00
### `StaticCallOnNonStaticToInstanceCallRector`
- class: `Rector\Php\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector`
Changes static call to instance call, where not useful
```diff
class Something
{
public function doWork()
{
}
}
class Another
{
public function run()
{
- return Something::doWork();
+ return (new Something)->doWork();
}
}
```
<br>
2018-12-31 11:50:32 +00:00
### `ExportToReflectionFunctionRector`
- class: `Rector\Php\Rector\StaticCall\ExportToReflectionFunctionRector`
Change export() to ReflectionFunction alternatives
```diff
-$reflectionFunction = ReflectionFunction::export('foo');
-$reflectionFunctionAsString = ReflectionFunction::export('foo', true);
+$reflectionFunction = new ReflectionFunction('foo');
+$reflectionFunctionAsString = (string) new ReflectionFunction('foo');
```
<br>
2018-10-21 22:26:45 +00:00
## Php\String_
### `SensitiveHereNowDocRector`
- class: `Rector\Php\Rector\String_\SensitiveHereNowDocRector`
Changes heredoc/nowdoc that contains closing word to safe wrapper name
```diff
-$value = <<<A
2018-10-21 22:26:45 +00:00
+$value = <<<A_WRAP
A
-A
2018-10-21 22:26:45 +00:00
+A_WRAP
```
<br>
## Php\Switch_
### `ReduceMultipleDefaultSwitchRector`
- class: `Rector\Php\Rector\Switch_\ReduceMultipleDefaultSwitchRector`
Remove first default switch, that is ignored
```diff
switch ($expr) {
default:
- echo "Hello World";
-
- default:
echo "Goodbye Moon!";
break;
}
```
<br>
2018-10-12 23:15:00 +00:00
## Php\Ternary
2018-08-01 20:09:34 +00:00
### `TernaryToSpaceshipRector`
- class: `Rector\Php\Rector\Ternary\TernaryToSpaceshipRector`
Use <=> spaceship instead of ternary with same effect
```diff
function order_func($a, $b) {
- return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
+ return $a <=> $b;
}
```
<br>
2018-10-12 23:15:00 +00:00
### `TernaryToNullCoalescingRector`
2018-08-01 20:09:34 +00:00
2018-10-12 23:15:00 +00:00
- class: `Rector\Php\Rector\Ternary\TernaryToNullCoalescingRector`
Changes unneeded null check to ?? operator
2018-08-01 20:09:34 +00:00
```diff
2018-10-12 23:15:00 +00:00
-$value === null ? 10 : $value;
+$value ?? 10;
2018-08-01 20:09:34 +00:00
```
```diff
2018-10-12 23:15:00 +00:00
-isset($value) ? $value : 10;
+$value ?? 10;
```
<br>
2018-10-12 23:15:00 +00:00
## Php\TryCatch
### `MultiExceptionCatchRector`
- class: `Rector\Php\Rector\TryCatch\MultiExceptionCatchRector`
Changes multi catch of same exception to single one | separated.
```diff
try {
// Some code...
-} catch (ExceptionType1 $exception) {
- $sameCode;
-} catch (ExceptionType2 $exception) {
+} catch (ExceptionType1 | ExceptionType2 $exception) {
$sameCode;
}
2018-08-01 20:09:34 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
## Php\Unset_
### `UnsetCastRector`
- class: `Rector\Php\Rector\Unset_\UnsetCastRector`
Removes (unset) cast
```diff
-$value = (unset) $value;
+$value = null;
```
<br>
2018-08-01 20:09:34 +00:00
## Sensio\FrameworkExtraBundle
### `TemplateAnnotationRector`
- class: `Rector\Sensio\Rector\FrameworkExtraBundle\TemplateAnnotationRector`
Turns `@Template` annotation to explicit method call in Controller of FrameworkExtraBundle in Symfony
2018-08-01 20:09:34 +00:00
```diff
-/**
- * @Template()
- */
public function indexAction()
{
+ return $this->render("index.html.twig");
}
```
<br>
2018-09-28 16:33:35 +00:00
## Silverstripe
### `ConstantToStaticCallRector`
- class: `Rector\Silverstripe\Rector\ConstantToStaticCallRector`
Turns defined constant to static method call.
```diff
-SS_DATABASE_NAME;
+Environment::getEnv("SS_DATABASE_NAME");
```
<br>
2018-09-28 16:33:35 +00:00
### `DefineConstantToStaticCallRector`
- class: `Rector\Silverstripe\Rector\DefineConstantToStaticCallRector`
Turns defined function call to static method call.
```diff
-defined("SS_DATABASE_NAME");
+Environment::getEnv("SS_DATABASE_NAME");
```
<br>
## Sylius\Review
### `ReplaceCreateMethodWithoutReviewerRector`
- class: `Rector\Sylius\Rector\Review\ReplaceCreateMethodWithoutReviewerRector`
2018-07-31 12:50:39 +00:00
Turns `createForSubjectWithReviewer()` with null review to standalone method in Sylius
2018-07-31 12:50:39 +00:00
```diff
-$this->createForSubjectWithReviewer($subject, null)
+$this->createForSubject($subject)
2018-07-31 12:50:39 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\Console
2018-08-01 20:09:34 +00:00
### `ConsoleExceptionToErrorEventConstantRector`
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Symfony\Rector\Console\ConsoleExceptionToErrorEventConstantRector`
2018-08-01 20:09:34 +00:00
Turns old event name with EXCEPTION to ERROR constant in Console in Symfony
2018-07-31 12:50:39 +00:00
```diff
2018-08-01 20:09:34 +00:00
-"console.exception"
+Symfony\Component\Console\ConsoleEvents::ERROR
```
```diff
-Symfony\Component\Console\ConsoleEvents::EXCEPTION
+Symfony\Component\Console\ConsoleEvents::ERROR
```
2018-07-31 12:50:39 +00:00
<br>
## Symfony\Controller
2018-07-31 12:50:39 +00:00
### `AddFlashRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\Symfony\Rector\Controller\AddFlashRector`
Turns long flash adding to short helper method in Controller in Symfony
```diff
class SomeController extends Controller
{
public function some(Request $request)
{
- $request->getSession()->getFlashBag()->add("success", "something");
+ $this->addFlash("success", "something");
}
}
2018-07-31 12:50:39 +00:00
```
<br>
### `RedirectToRouteRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\Symfony\Rector\Controller\RedirectToRouteRector`
2018-07-31 12:50:39 +00:00
Turns redirect to route to short helper method in Controller in Symfony
2018-07-31 12:50:39 +00:00
```diff
-$this->redirect($this->generateUrl("homepage"));
+$this->redirectToRoute("homepage");
```
<br>
### `ActionSuffixRemoverRector`
- class: `Rector\Symfony\Rector\Controller\ActionSuffixRemoverRector`
Removes Action suffixes from methods in Symfony Controllers
2018-07-31 12:50:39 +00:00
```diff
class SomeController
{
- public function indexAction()
+ public function index()
{
}
}
2018-07-31 12:50:39 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\DependencyInjection
2018-08-01 20:09:34 +00:00
### `ContainerBuilderCompileEnvArgumentRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Symfony\Rector\DependencyInjection\ContainerBuilderCompileEnvArgumentRector`
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
Turns old default value to parameter in ContinerBuilder->build() method in DI in Symfony
2018-07-31 12:50:39 +00:00
```diff
2018-08-01 20:09:34 +00:00
-$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder(); $containerBuilder->compile();
+$containerBuilder = new Symfony\Component\DependencyInjection\ContainerBuilder(); $containerBuilder->compile(true);
2018-07-31 12:50:39 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\Form
### `FormIsValidRector`
2018-07-31 12:50:39 +00:00
- class: `Rector\Symfony\Rector\Form\FormIsValidRector`
Adds `$form->isSubmitted()` validatoin to all `$form->isValid()` calls in Form in Symfony
2018-07-31 12:50:39 +00:00
```diff
-if ($form->isValid()) {
+if ($form->isSubmitted() && $form->isValid()) {
}
2018-07-31 12:50:39 +00:00
```
<br>
### `OptionNameRector`
- class: `Rector\Symfony\Rector\Form\OptionNameRector`
Turns old option names to new ones in FormTypes in Form in Symfony
2018-07-31 12:50:39 +00:00
```diff
$builder = new FormBuilder;
-$builder->add("...", ["precision" => "...", "virtual" => "..."];
+$builder->add("...", ["scale" => "...", "inherit_data" => "..."];
```
2018-07-31 12:50:39 +00:00
<br>
2018-08-01 20:09:34 +00:00
### `StringFormTypeToClassRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Symfony\Rector\Form\StringFormTypeToClassRector`
2018-08-01 20:09:34 +00:00
Turns string Form Type references to their CONSTANT alternatives in FormTypes in Form in Symfony
```diff
2018-09-28 16:33:35 +00:00
$formBuilder = new Symfony\Component\Form\FormBuilder;
-$formBuilder->add('name', 'form.type.text');
+$form->add('name', \Symfony\Component\Form\Extension\Core\Type\TextType::class);
2018-07-31 12:50:39 +00:00
```
<br>
### `FormTypeGetParentRector`
- class: `Rector\Symfony\Rector\Form\FormTypeGetParentRector`
Turns string Form Type references to their CONSTANT alternatives in `getParent()` and `getExtendedType()` methods in Form in Symfony
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
```diff
-function getParent() { return "collection"; }
+function getParent() { return CollectionType::class; }
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
```diff
-function getExtendedType() { return "collection"; }
+function getExtendedType() { return CollectionType::class; }
2018-07-31 12:50:39 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\FrameworkBundle
### `GetParameterToConstructorInjectionRector`
2018-05-04 22:30:32 +00:00
- class: `Rector\Symfony\Rector\FrameworkBundle\GetParameterToConstructorInjectionRector`
Turns fetching of parameters via `getParameter()` in ContainerAware to constructor injection in Command and Controller in Symfony
2018-05-04 22:30:32 +00:00
```diff
-class MyCommand extends ContainerAwareCommand
+class MyCommand extends Command
2018-05-04 22:30:32 +00:00
{
+ private $someParameter;
+
+ public function __construct($someParameter)
2018-07-31 12:50:39 +00:00
+ {
+ $this->someParameter = $someParameter;
+ }
+
public function someMethod()
{
- $this->getParameter('someParameter');
+ $this->someParameter;
2018-05-04 22:30:32 +00:00
}
}
```
<br>
### `GetToConstructorInjectionRector`
- class: `Rector\Symfony\Rector\FrameworkBundle\GetToConstructorInjectionRector`
2018-05-04 22:30:32 +00:00
Turns fetching of dependencies via `$this->get()` to constructor injection in Command and Controller in Symfony
2018-05-04 22:30:32 +00:00
```diff
-class MyCommand extends ContainerAwareCommand
+class MyCommand extends Command
2018-05-04 22:30:32 +00:00
{
+ public function __construct(SomeService $someService)
+ {
+ $this->someService = $someService;
+ }
+
2018-07-31 12:50:39 +00:00
public function someMethod()
{
- // ...
- $this->get('some_service');
+ $this->someService;
2018-07-31 12:50:39 +00:00
}
2018-05-04 22:30:32 +00:00
}
```
<br>
### `ContainerGetToConstructorInjectionRector`
2018-05-04 22:30:32 +00:00
- class: `Rector\Symfony\Rector\FrameworkBundle\ContainerGetToConstructorInjectionRector`
Turns fetching of dependencies via `$container->get()` in ContainerAware to constructor injection in Command and Controller in Symfony
2018-05-04 22:30:32 +00:00
```diff
-final class SomeCommand extends ContainerAwareCommand
+final class SomeCommand extends Command
2018-05-04 22:30:32 +00:00
{
+ public function __construct(SomeService $someService)
2018-05-04 22:30:32 +00:00
+ {
+ $this->someService = $someService;
2018-05-04 22:30:32 +00:00
+ }
+
public function someMethod()
2018-05-04 22:30:32 +00:00
{
// ...
- $this->getContainer()->get('some_service');
- $this->container->get('some_service');
+ $this->someService;
+ $this->someService;
2018-05-04 22:30:32 +00:00
}
}
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\HttpKernel
2018-08-01 20:09:34 +00:00
### `GetRequestRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Symfony\Rector\HttpKernel\GetRequestRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Turns fetching of dependencies via `$this->get()` to constructor injection in Command and Controller in Symfony
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
+use Symfony\Component\HttpFoundation\Request;
+
class SomeController
{
- public function someAction()
+ public action(Request $request)
{
- $this->getRequest()->...();
+ $request->...();
}
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
## Symfony\MethodCall
2018-10-23 18:58:57 +00:00
### `CascadeValidationFormBuilderRector`
- class: `Rector\Symfony\Rector\MethodCall\CascadeValidationFormBuilderRector`
Change "cascade_validation" option to specific node attribute
```diff
class SomeController
{
public function someMethod()
{
- $form = $this->createFormBuilder($article, ['cascade_validation' => true])
- ->add('author', new AuthorType())
+ $form = $this->createFormBuilder($article)
+ ->add('author', new AuthorType(), [
+ 'constraints' => new \Symfony\Component\Validator\Constraints\Valid(),
+ ])
->getForm();
}
protected function createFormBuilder()
{
return new FormBuilder();
}
}
```
<br>
2018-10-21 22:26:45 +00:00
### `ReadOnlyOptionToAttributeRector`
2018-10-12 23:15:00 +00:00
2018-10-21 22:26:45 +00:00
- class: `Rector\Symfony\Rector\MethodCall\ReadOnlyOptionToAttributeRector`
2018-10-12 23:15:00 +00:00
2018-10-21 22:26:45 +00:00
Change "read_only" option in form to attribute
2018-10-12 23:15:00 +00:00
```diff
2018-10-21 22:26:45 +00:00
use Symfony\Component\Form\FormBuilderInterface;
function buildForm(FormBuilderInterface $builder, array $options)
{
- $builder->add('cuid', TextType::class, ['read_only' => true]);
+ $builder->add('cuid', TextType::class, ['attr' => [read_only' => true]]);
}
2018-10-12 23:15:00 +00:00
```
<br>
2018-10-23 18:58:57 +00:00
### `FormTypeInstanceToClassConstRector`
2018-10-23 18:58:57 +00:00
- class: `Rector\Symfony\Rector\MethodCall\FormTypeInstanceToClassConstRector`
2018-10-23 18:58:57 +00:00
Changes createForm(new FormType), add(new FormType) to ones with "FormType::class"
2018-10-23 18:58:57 +00:00
```diff
class SomeController
{
public function action()
{
- $form = $this->createForm(new TeamType, $entity, [
+ $form = $this->createForm(TeamType::class, $entity, [
'action' => $this->generateUrl('teams_update', ['id' => $entity->getId()]),
'method' => 'PUT',
- ]);
+ ));
}
}
```
<br>
## Symfony\New_
### `StringToArrayArgumentProcessRector`
- class: `Rector\Symfony\Rector\New_\StringToArrayArgumentProcessRector`
Changes Process string argument to an array
```diff
use Symfony\Component\Process\Process;
-$process = new Process('ls -l');
+$process = new Process(['ls', '-l']);
```
<br>
### `RootNodeTreeBuilderRector`
- class: `Rector\Symfony\Rector\New_\RootNodeTreeBuilderRector`
Changes Process string argument to an array
```diff
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
-$treeBuilder = new TreeBuilder();
-$rootNode = $treeBuilder->root('acme_root');
+$treeBuilder = new TreeBuilder('acme_root');
+$rootNode = $treeBuilder->getRootNode();
$rootNode->someCall();
2018-10-23 18:58:57 +00:00
```
<br>
## Symfony\Process
### `ProcessBuilderGetProcessRector`
2018-05-04 22:30:32 +00:00
- class: `Rector\Symfony\Rector\Process\ProcessBuilderGetProcessRector`
2018-05-04 22:30:32 +00:00
Removes `$processBuilder->getProcess()` calls to $processBuilder in Process in Symfony, because ProcessBuilder was removed. This is part of multi-step Rector and has very narrow focus.
2018-07-31 12:50:39 +00:00
```diff
$processBuilder = new Symfony\Component\Process\ProcessBuilder;
-$process = $processBuilder->getProcess();
-$commamdLine = $processBuilder->getProcess()->getCommandLine();
+$process = $processBuilder;
+$commamdLine = $processBuilder->getCommandLine();
2018-05-04 22:30:32 +00:00
```
<br>
### `ProcessBuilderInstanceRector`
- class: `Rector\Symfony\Rector\Process\ProcessBuilderInstanceRector`
Turns `ProcessBuilder::instance()` to new ProcessBuilder in Process in Symfony. Part of multi-step Rector.
```diff
-$processBuilder = Symfony\Component\Process\ProcessBuilder::instance($args);
+$processBuilder = new Symfony\Component\Process\ProcessBuilder($args);
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\Validator
2018-08-01 20:09:34 +00:00
### `ConstraintUrlOptionRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Symfony\Rector\Validator\ConstraintUrlOptionRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Turns true value to `Url::CHECK_DNS_TYPE_ANY` in Validator in Symfony.
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-$constraint = new Url(["checkDNS" => true]);
+$constraint = new Url(["checkDNS" => Url::CHECK_DNS_TYPE_ANY]);
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\VarDumper
2018-08-01 20:09:34 +00:00
### `VarDumperTestTraitMethodArgsRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Symfony\Rector\VarDumper\VarDumperTestTraitMethodArgsRector`
2018-08-01 20:09:34 +00:00
Adds new `$format` argument in `VarDumperTestTrait->assertDumpEquals()` in Validator in Symfony.
2018-05-04 22:30:32 +00:00
```diff
2018-08-10 19:07:08 +00:00
-$varDumperTestTrait->assertDumpEquals($dump, $data, $mesage = "");
+$varDumperTestTrait->assertDumpEquals($dump, $data, $context = null, $mesage = "");
2018-05-04 22:30:32 +00:00
```
2018-08-01 20:09:34 +00:00
```diff
2018-08-10 19:07:08 +00:00
-$varDumperTestTrait->assertDumpMatchesFormat($dump, $format, $mesage = "");
+$varDumperTestTrait->assertDumpMatchesFormat($dump, $format, $context = null, $mesage = "");
2018-08-01 20:09:34 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Symfony\Yaml
2018-05-04 22:30:32 +00:00
### `ParseFileRector`
2018-09-28 16:33:35 +00:00
- class: `Rector\Symfony\Rector\Yaml\ParseFileRector`
session > use_strict_mode is true by default and can be removed
2018-09-28 16:33:35 +00:00
```diff
-session > use_strict_mode: true
+session:
2018-09-28 16:33:35 +00:00
```
<br>
2018-09-28 16:33:35 +00:00
## Twig
### `SimpleFunctionAndFilterRector`
- class: `Rector\Twig\Rector\SimpleFunctionAndFilterRector`
Changes Twig_Function_Method to Twig_SimpleFunction calls in TwigExtension.
```diff
class SomeExtension extends Twig_Extension
{
public function getFunctions()
{
return [
- 'is_mobile' => new Twig_Function_Method($this, 'isMobile'),
+ new Twig_SimpleFunction('is_mobile', [$this, 'isMobile']),
];
}
- public function getFilters()
+ public function getFilteres()
{
return [
- 'is_mobile' => new Twig_Filter_Method($this, 'isMobile'),
+ new Twig_SimpleFilter('is_mobile', [$this, 'isMobile']),
];
}
}
```
<br>
2018-08-01 20:09:34 +00:00
---
## General
2018-08-01 20:09:34 +00:00
- [Annotation](#annotation)
- [Argument](#argument)
- [Assign](#assign)
2018-12-14 19:35:35 +00:00
- [ClassMethod](#classmethod)
2018-08-01 20:09:34 +00:00
- [Class_](#class_)
- [Constant](#constant)
- [DependencyInjection](#dependencyinjection)
2019-01-25 16:03:35 +00:00
- [Factory](#factory)
2018-08-01 20:09:34 +00:00
- [Function_](#function_)
- [Interface_](#interface_)
- [MagicDisclosure](#magicdisclosure)
- [MethodBody](#methodbody)
- [MethodCall](#methodcall)
- [Namespace_](#namespace_)
- [Property](#property)
2018-09-28 16:33:35 +00:00
- [Psr4](#psr4)
2018-08-01 20:09:34 +00:00
- [RepositoryAsService](#repositoryasservice)
2018-08-12 18:34:27 +00:00
- [StaticCall](#staticcall)
2018-08-01 20:09:34 +00:00
- [Typehint](#typehint)
- [Visibility](#visibility)
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
## Annotation
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
### `AnnotationReplacerRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Annotation\AnnotationReplacerRector`
2018-08-01 20:09:34 +00:00
Turns defined annotations above properties and methods to their new values.
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Annotation\AnnotationReplacerRector:
PHPUnit\Framework\TestCase:
test: scenario
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
class SomeTest extends PHPUnit\Framework\TestCase
{
2018-08-10 19:07:08 +00:00
- /**
- * @test
+ /**
+ * @scenario
*/
2018-08-01 20:09:34 +00:00
public function someMethod()
{
}
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Argument
2018-08-01 20:09:34 +00:00
### `ArgumentAdderRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Argument\ArgumentAdderRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
This Rector adds new default arguments in calls of defined methods and class types.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Argument\ArgumentAdderRector:
2018-10-21 22:26:45 +00:00
SomeExampleClass:
someMethod:
-
default_value: 'true'
2018-05-04 22:30:32 +00:00
```
2018-08-01 20:09:34 +00:00
2018-08-01 20:09:34 +00:00
```diff
2018-10-21 22:26:45 +00:00
$someObject = new SomeExampleClass;
2018-08-01 20:09:34 +00:00
-$someObject->someMethod();
+$someObject->someMethod(true);
```
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Argument\ArgumentAdderRector:
2018-10-21 22:26:45 +00:00
SomeExampleClass:
someMethod:
-
default_value: 'true'
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
2018-05-04 22:30:32 +00:00
```diff
2018-10-21 22:26:45 +00:00
class MyCustomClass extends SomeExampleClass
2018-07-31 12:50:39 +00:00
{
2018-08-01 20:09:34 +00:00
- public function someMethod()
+ public function someMethod($value = true)
{
}
2018-07-31 12:50:39 +00:00
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
### `ArgumentRemoverRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Argument\ArgumentRemoverRector`
2018-08-01 20:09:34 +00:00
Removes defined arguments in defined methods and their calls.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Argument\ArgumentRemoverRector:
2018-10-21 22:26:45 +00:00
ExampleClass:
someMethod:
-
value: 'true'
2018-08-01 20:09:34 +00:00
```
2018-08-01 20:09:34 +00:00
```diff
2018-08-01 20:09:34 +00:00
$someObject = new SomeClass;
-$someObject->someMethod(true);
+$someObject->someMethod();'
```
<br>
2018-08-01 20:09:34 +00:00
### `ArgumentDefaultValueReplacerRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Argument\ArgumentDefaultValueReplacerRector`
2018-08-01 20:09:34 +00:00
Replaces defined map of arguments in defined methods and their calls.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Argument\ArgumentDefaultValueReplacerRector:
SomeExampleClass:
someMethod:
-
2018-10-21 22:26:45 +00:00
-
before: 'SomeClass::OLD_CONSTANT'
after: 'false'
```
2018-08-01 20:09:34 +00:00
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
$someObject = new SomeClass;
-$someObject->someMethod(SomeClass::OLD_CONSTANT);
+$someObject->someMethod(false);'
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Assign
2018-08-01 20:09:34 +00:00
### `PropertyAssignToMethodCallRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Assign\PropertyAssignToMethodCallRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Turns property assign of specific type and property name to method call
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Assign\PropertyAssignToMethodCallRector:
2018-10-21 22:26:45 +00:00
$oldPropertiesToNewMethodCallsByType:
SomeClass:
oldPropertyName: oldProperty
newMethodName: newMethodCall
2018-05-04 22:30:32 +00:00
```
2018-08-01 20:09:34 +00:00
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-$someObject = new SomeClass;
-$someObject->oldProperty = false;
+$someObject = new SomeClass;
+$someObject->newMethodCall(false);
2018-05-04 22:30:32 +00:00
```
<br>
2018-12-14 19:35:35 +00:00
## ClassMethod
### `WrapReturnRector`
- class: `Rector\Rector\ClassMethod\WrapReturnRector`
2018-12-14 19:38:47 +00:00
Wrap return value of specific method
```yaml
services:
Rector\Rector\ClassMethod\WrapReturnRector:
SomeClass:
getItem: array
```
2018-12-14 19:35:35 +00:00
```diff
final class SomeClass
{
public function getItem()
{
- return 1;
+ return [1];
}
}
```
<br>
2018-08-01 20:09:34 +00:00
## Class_
2018-08-01 20:09:34 +00:00
### `ClassReplacerRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Class_\ClassReplacerRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Replaces defined classes by new ones.
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Class_\ClassReplacerRector:
SomeOldClass: SomeNewClass
2018-07-31 12:50:39 +00:00
```
2018-08-01 20:09:34 +00:00
2018-07-31 12:50:39 +00:00
```diff
2018-10-21 22:26:45 +00:00
-use SomeOldClass;
+use SomeNewClass;
-function (SomeOldClass $someOldClass): SomeOldClass
+function (SomeNewClass $someOldClass): SomeNewClass
{
- if ($someOldClass instanceof SomeOldClass) {
- return new SomeOldClass;
+ if ($someOldClass instanceof SomeNewClass) {
+ return new SomeNewClass;
}
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
### `ParentClassToTraitsRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Class_\ParentClassToTraitsRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Replaces parent class to specific traits
```yaml
services:
Rector\Rector\Class_\ParentClassToTraitsRector:
Nette\Object:
- Nette\SmartObject
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-class SomeClass extends Nette\Object
+class SomeClass
{
+ use Nette\SmartObject;
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Constant
### `RenameClassConstantsUseToStringsRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Constant\RenameClassConstantsUseToStringsRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Replaces constant by value
```yaml
services:
Rector\Rector\Constant\RenameClassConstantsUseToStringsRector:
2018-10-21 22:26:45 +00:00
Nette\Configurator:
2018-08-01 20:09:34 +00:00
DEVELOPMENT: development
PRODUCTION: production
```
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-$value === Nette\Configurator::DEVELOPMENT
+$value === "development"
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
### `ClassConstantReplacerRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Constant\ClassConstantReplacerRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Replaces defined class constants in their calls.
```yaml
services:
Rector\Rector\Constant\ClassConstantReplacerRector:
SomeClass:
OLD_CONSTANT: NEW_CONSTANT
OTHER_OLD_CONSTANT: 'DifferentClass::NEW_CONSTANT'
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-$value = SomeClass::OLD_CONSTANT;
-$value = SomeClass::OTHER_OLD_CONSTANT;
2018-08-01 20:09:34 +00:00
+$value = SomeClass::NEW_CONSTANT;
+$value = DifferentClass::NEW_CONSTANT;
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## DependencyInjection
### `AnnotatedPropertyInjectToConstructorInjectionRector`
- class: `Rector\Rector\Architecture\DependencyInjection\AnnotatedPropertyInjectToConstructorInjectionRector`
Turns non-private properties with `@annotation` to private properties and constructor injection
```yaml
services:
Rector\Rector\Architecture\DependencyInjection\AnnotatedPropertyInjectToConstructorInjectionRector:
$annotation: inject
```
```diff
/**
* @var SomeService
- * @inject
*/
-public $someService;
+private $someService;
+
+public function __construct(SomeService $someService)
+{
+ $this->someService = $someService;
+}
```
<br>
2018-10-23 18:58:57 +00:00
### `ReplaceVariableByPropertyFetchRector`
- class: `Rector\Rector\Architecture\DependencyInjection\ReplaceVariableByPropertyFetchRector`
Turns variable in controller action to property fetch, as follow up to action injection variable to property change.
```diff
final class SomeController
{
/**
* @var ProductRepository
*/
private $productRepository;
public function __construct(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
public function default()
{
- $products = $productRepository->fetchAll();
+ $products = $this->productRepository->fetchAll();
}
}
```
<br>
2018-05-04 22:30:32 +00:00
2018-10-21 22:26:45 +00:00
### `ActionInjectionToConstructorInjectionRector`
2018-10-12 23:15:00 +00:00
2018-10-21 22:26:45 +00:00
- class: `Rector\Rector\Architecture\DependencyInjection\ActionInjectionToConstructorInjectionRector`
2018-10-12 23:15:00 +00:00
2018-10-21 22:26:45 +00:00
Turns action injection in Controllers to constructor injection
2018-10-12 23:15:00 +00:00
2018-10-21 22:26:45 +00:00
```diff
final class SomeController
{
- public function default(ProductRepository $productRepository)
+ /**
+ * @var ProductRepository
+ */
+ private $productRepository;
+ public function __construct(ProductRepository $productRepository)
{
- $products = $productRepository->fetchAll();
+ $this->productRepository = $productRepository;
+ }
+
+ public function default()
+ {
+ $products = $this->productRepository->fetchAll();
}
}
2018-10-12 23:15:00 +00:00
```
<br>
2019-01-25 16:03:35 +00:00
## Factory
### `NewObjectToFactoryCreateRector`
- class: `Rector\Rector\Architecture\Factory\NewObjectToFactoryCreateRector`
Replaces creating object instances with "new" keyword with factory method.
```yaml
services:
Rector\Rector\Architecture\Factory\NewObjectToFactoryCreateRector:
MyClass:
class: MyClassFactory
method: create
```
```diff
class SomeClass
{
+ /**
+ * @var \MyClassFactory
+ */
+ private $myClassFactory;
+
public function example() {
- new MyClass($argument);
+ $this->myClassFactory->create($argument);
}
}
```
<br>
2018-10-21 22:26:45 +00:00
## Function_
2018-10-12 23:15:00 +00:00
### `FunctionToMethodCallRector`
2018-10-23 18:58:57 +00:00
- class: `Rector\Rector\Function_\FunctionToMethodCallRector`
2018-10-23 18:58:57 +00:00
Turns defined function calls to local method calls.
2018-10-23 18:58:57 +00:00
```yaml
services:
Rector\Rector\Function_\FunctionToMethodCallRector:
view:
- this
- render
2018-10-23 18:58:57 +00:00
```
```diff
-view("...", []);
+$this->render("...", []);
2018-10-23 18:58:57 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
### `FunctionToStaticCallRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Function_\FunctionToStaticCallRector`
Turns defined function call to static method call.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Function_\FunctionToStaticCallRector:
view:
- SomeStaticClass
- render
2018-08-01 20:09:34 +00:00
```
```diff
-view("...", []);
+SomeClass::render("...", []);
2018-08-01 20:09:34 +00:00
```
<br>
2018-08-12 18:34:27 +00:00
### `FunctionReplaceRector`
2018-08-12 18:34:27 +00:00
- class: `Rector\Rector\Function_\FunctionReplaceRector`
Turns defined function call new one.
2018-08-12 18:34:27 +00:00
```yaml
services:
Rector\Rector\Function_\FunctionReplaceRector:
view: Laravel\Templating\render
2018-08-12 18:34:27 +00:00
```
```diff
-view("...", []);
+Laravel\Templating\render("...", []);
2018-08-12 18:34:27 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Interface_
2019-01-22 20:34:38 +00:00
### `RemoveInterfacesRector`
- class: `Rector\Rector\Interface_\RemoveInterfacesRector`
Removes interfaces usage from class.
```yaml
services:
Rector\Rector\Interface_\RemoveInterfacesRector:
- SomeInterface
```
```diff
-class SomeClass implements SomeInterface
+class SomeClass
{
}
```
<br>
2018-08-01 20:09:34 +00:00
### `MergeInterfacesRector`
- class: `Rector\Rector\Interface_\MergeInterfacesRector`
Merges old interface to a new one, that already has its methods
```yaml
services:
Rector\Rector\Interface_\MergeInterfacesRector:
SomeOldInterface: SomeInterface
2018-08-01 20:09:34 +00:00
```
```diff
-class SomeClass implements SomeInterface, SomeOldInterface
+class SomeClass implements SomeInterface
{
}
```
<br>
2018-08-01 20:09:34 +00:00
## MagicDisclosure
### `ToStringToMethodCallRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\MagicDisclosure\ToStringToMethodCallRector`
2018-07-31 12:50:39 +00:00
2018-08-10 19:07:08 +00:00
Turns defined code uses of "__toString()" method to specific method calls.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\MagicDisclosure\ToStringToMethodCallRector:
SomeObject: getPath
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
```diff
2018-08-10 19:07:08 +00:00
$someValue = new SomeObject;
2018-08-01 20:09:34 +00:00
-$result = (string) $someValue;
-$result = $someValue->__toString();
+$result = $someValue->getPath();
+$result = $someValue->getPath();
2018-07-31 12:50:39 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
### `GetAndSetToMethodCallRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\MagicDisclosure\GetAndSetToMethodCallRector`
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
Turns defined `__get`/`__set` to specific method calls.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\MagicDisclosure\GetAndSetToMethodCallRector:
SomeContainer:
set: addService
2018-08-01 20:09:34 +00:00
```
2018-07-31 12:50:39 +00:00
```diff
2018-08-10 19:07:08 +00:00
$container = new SomeContainer;
2018-08-01 20:09:34 +00:00
-$container->someService = $someService;
+$container->setService("someService", $someService);
```
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\MagicDisclosure\GetAndSetToMethodCallRector:
$typeToMethodCalls:
SomeContainer:
get: getService
2018-07-31 12:50:39 +00:00
```
2018-08-01 20:09:34 +00:00
2018-08-01 20:09:34 +00:00
```diff
2018-08-10 19:07:08 +00:00
$container = new SomeContainer;
2018-08-01 20:09:34 +00:00
-$someService = $container->someService;
+$someService = $container->getService("someService");
```
2018-05-04 22:30:32 +00:00
<br>
2018-08-01 20:09:34 +00:00
### `UnsetAndIssetToMethodCallRector`
- class: `Rector\Rector\MagicDisclosure\UnsetAndIssetToMethodCallRector`
Turns defined `__isset`/`__unset` calls to specific method calls.
```yaml
services:
Rector\Rector\MagicDisclosure\UnsetAndIssetToMethodCallRector:
SomeContainer:
isset: hasService
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
$container = new SomeContainer;
2018-08-01 20:09:34 +00:00
-isset($container["someKey"]);
+$container->hasService("someKey");
```
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\MagicDisclosure\UnsetAndIssetToMethodCallRector:
SomeContainer:
unset: removeService
2018-08-01 20:09:34 +00:00
```
2018-08-01 20:09:34 +00:00
2018-08-01 20:09:34 +00:00
```diff
$container = new SomeContainer;
-unset($container["someKey"]);
2018-08-01 20:09:34 +00:00
+$container->removeService("someKey");
```
<br>
2018-08-01 20:09:34 +00:00
## MethodBody
### `FluentReplaceRector`
- class: `Rector\Rector\MethodBody\FluentReplaceRector`
2018-09-28 16:33:35 +00:00
Turns fluent interface calls to classic ones.
```yaml
services:
Rector\Rector\MethodBody\FluentReplaceRector:
-
2018-10-21 22:26:45 +00:00
- SomeExampleClass
2018-09-28 16:33:35 +00:00
```
```diff
$someClass = new SomeClass();
-$someClass->someFunction()
- ->otherFunction();
+$someClass->someFunction();
+$someClass->otherFunction();
```
<br>
2018-09-28 16:33:35 +00:00
### `NormalToFluentRector`
- class: `Rector\Rector\MethodBody\NormalToFluentRector`
Turns fluent interface calls to classic ones.
```yaml
services:
Rector\Rector\MethodBody\NormalToFluentRector:
SomeClass:
- someFunction
- otherFunction
2018-09-28 16:33:35 +00:00
```
```diff
$someObject = new SomeClass();
-$someObject->someFunction();
-$someObject->otherFunction();
+$someObject->someFunction()
+ ->otherFunction();
```
<br>
2018-09-28 16:33:35 +00:00
### `ReturnThisRemoveRector`
- class: `Rector\Rector\MethodBody\ReturnThisRemoveRector`
Removes "return $this;" from *fluent interfaces* for specified classes.
```yaml
services:
Rector\Rector\MethodBody\ReturnThisRemoveRector:
-
2018-10-21 22:26:45 +00:00
- SomeExampleClass
2018-09-28 16:33:35 +00:00
```
2018-08-01 20:09:34 +00:00
```diff
class SomeClass
{
public function someFunction()
{
- return $this;
}
public function otherFunction()
{
- return $this;
}
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-10-23 18:58:57 +00:00
## MethodCall
2018-10-23 18:58:57 +00:00
2018-10-21 22:26:45 +00:00
### `MethodCallToAnotherMethodCallWithArgumentsRector`
2018-10-21 22:26:45 +00:00
- class: `Rector\Rector\MethodCall\MethodCallToAnotherMethodCallWithArgumentsRector`
2018-05-04 22:30:32 +00:00
2018-10-21 22:26:45 +00:00
Turns old method call with specfici type to new one with arguments
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
2018-10-21 22:26:45 +00:00
Rector\Rector\MethodCall\MethodCallToAnotherMethodCallWithArgumentsRector:
Nette\DI\ServiceDefinition:
setInject:
-
- addTag
-
- inject
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
2018-10-21 22:26:45 +00:00
$serviceDefinition = new Nette\DI\ServiceDefinition;
-$serviceDefinition->setInject();
+$serviceDefinition->addTag('inject');
2018-05-04 22:30:32 +00:00
```
<br>
### `MethodNameReplacerRector`
- class: `Rector\Rector\MethodCall\MethodNameReplacerRector`
Turns method names to new ones.
```yaml
services:
Rector\Rector\MethodCall\MethodNameReplacerRector:
SomeExampleClass:
oldMethod: newMethod
```
```diff
$someObject = new SomeExampleClass;
-$someObject->oldMethod();
+$someObject->newMethod();
```
<br>
2018-10-23 18:58:57 +00:00
### `StaticMethodNameReplacerRector`
2018-10-23 18:58:57 +00:00
- class: `Rector\Rector\MethodCall\StaticMethodNameReplacerRector`
2018-10-21 22:26:45 +00:00
Turns method names to new ones.
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
2018-10-23 18:58:57 +00:00
Rector\Rector\MethodCall\StaticMethodNameReplacerRector:
SomeClass:
oldMethod:
- AnotherExampleClass
- newStaticMethod
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
```diff
2018-10-23 18:58:57 +00:00
-SomeClass::oldStaticMethod();
+AnotherExampleClass::newStaticMethod();
2018-05-04 22:30:32 +00:00
```
2018-08-01 20:09:34 +00:00
```yaml
services:
2018-08-10 19:07:08 +00:00
Rector\Rector\MethodCall\StaticMethodNameReplacerRector:
2018-10-23 18:58:57 +00:00
$oldToNewMethodByClasses:
2018-08-01 20:09:34 +00:00
SomeClass:
2018-10-23 18:58:57 +00:00
oldMethod: newStaticMethod
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-SomeClass::oldStaticMethod();
+SomeClass::newStaticMethod();
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Namespace_
### `NamespaceReplacerRector`
- class: `Rector\Rector\Namespace_\NamespaceReplacerRector`
2018-08-01 20:09:34 +00:00
Replaces old namespace by new one.
2018-05-05 00:04:41 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Namespace_\NamespaceReplacerRector:
$oldToNewNamespaces:
SomeOldNamespace: SomeNewNamespace
```
2018-05-05 00:04:41 +00:00
2018-08-01 20:09:34 +00:00
2018-08-01 20:09:34 +00:00
```diff
-$someObject = new SomeOldNamespace\SomeClass;
+$someObject = new SomeNewNamespace\SomeClass;
2018-05-05 00:04:41 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
### `PseudoNamespaceToNamespaceRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Namespace_\PseudoNamespaceToNamespaceRector`
2018-08-01 20:09:34 +00:00
Replaces defined Pseudo_Namespaces by Namespace\Ones.
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Namespace_\PseudoNamespaceToNamespaceRector:
-
Some_: { }
```
```diff
-$someService = new Some_Object;
+$someService = new Some\Object;
```
```yaml
services:
Rector\Rector\Namespace_\PseudoNamespaceToNamespaceRector:
-
Some_:
- Some_Class_To_Keep
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
-$someService = new Some_Object;
+$someService = new Some\Object;
$someClassToKeep = new Some_Class_To_Keep;
2018-05-04 22:30:32 +00:00
```
<br>
2018-08-01 20:09:34 +00:00
## Property
2018-08-01 20:09:34 +00:00
### `PropertyToMethodRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Property\PropertyToMethodRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Replaces properties assign calls be defined methods.
2018-07-31 12:50:39 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Property\PropertyToMethodRector:
$perClassPropertyToMethods:
SomeObject:
property:
2018-09-28 16:33:35 +00:00
get: getProperty
set: setProperty
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```diff
-$result = $object->property;
-$object->property = $value;
+$result = $object->getProperty();
+$object->setProperty($value);
```
2018-09-28 16:33:35 +00:00
```yaml
services:
Rector\Rector\Property\PropertyToMethodRector:
$perClassPropertyToMethods:
SomeObject:
property:
get:
method: getConfig
arguments:
- someArg
```
```diff
-$result = $object->property;
+$result = $object->getProperty('someArg');
```
<br>
2018-08-01 20:09:34 +00:00
### `PropertyNameReplacerRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Property\PropertyNameReplacerRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Replaces defined old properties by new ones.
```yaml
services:
Rector\Rector\Property\PropertyNameReplacerRector:
2018-10-23 18:58:57 +00:00
$oldToNewPropertyByTypes:
2018-08-01 20:09:34 +00:00
SomeClass:
someOldProperty: someNewProperty
```
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
-$someObject->someOldProperty;
+$someObject->someNewProperty;
2018-05-04 22:30:32 +00:00
```
<br>
2018-09-28 16:33:35 +00:00
## Psr4
### `MultipleClassFileToPsr4ClassesRector`
- class: `Rector\Rector\Psr4\MultipleClassFileToPsr4ClassesRector`
Turns namespaced classes in one file to standalone PSR-4 classes.
```diff
+// new file: "app/Exceptions/FirstException.php"
namespace App\Exceptions;
use Exception;
final class FirstException extends Exception
{
}
+
+// new file: "app/Exceptions/SecondException.php"
+namespace App\Exceptions;
+
+use Exception;
final class SecondException extends Exception
{
}
```
<br>
## RepositoryAsService
### `ReplaceParentRepositoryCallsByRepositoryPropertyRector`
- class: `Rector\Rector\Architecture\RepositoryAsService\ReplaceParentRepositoryCallsByRepositoryPropertyRector`
Handles method calls in child of Doctrine EntityRepository and moves them to "$this->repository" property.
```diff
<?php
use Doctrine\ORM\EntityRepository;
class SomeRepository extends EntityRepository
{
public function someMethod()
{
- return $this->findAll();
+ return $this->repository->findAll();
}
}
```
<br>
### `ServiceLocatorToDIRector`
- class: `Rector\Rector\Architecture\RepositoryAsService\ServiceLocatorToDIRector`
2018-05-04 22:30:32 +00:00
Turns "$this->getRepository()" in Symfony Controller to constructor injection and private property access.
2018-05-04 22:30:32 +00:00
```diff
class ProductController extends Controller
2018-07-31 12:50:39 +00:00
{
+ /**
+ * @var ProductRepository
+ */
+ private $productRepository;
+
+ public function __construct(ProductRepository $productRepository)
2018-07-31 12:50:39 +00:00
+ {
+ $this->productRepository = $productRepository;
2018-07-31 12:50:39 +00:00
+ }
+
public function someAction()
2018-07-31 12:50:39 +00:00
{
$entityManager = $this->getDoctrine()->getManager();
- $entityManager->getRepository('SomethingBundle:Product')->findSomething(...);
+ $this->productRepository->findSomething(...);
2018-07-31 12:50:39 +00:00
}
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-10-23 18:58:57 +00:00
### `MoveRepositoryFromParentToConstructorRector`
- class: `Rector\Rector\Architecture\RepositoryAsService\MoveRepositoryFromParentToConstructorRector`
2018-05-04 22:30:32 +00:00
Turns parent EntityRepository class to constructor dependency
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Architecture\RepositoryAsService\MoveRepositoryFromParentToConstructorRector:
$entityRepositoryClass: Doctrine\ORM\EntityRepository
$entityManagerClass: Doctrine\ORM\EntityManager
```
2018-05-04 22:30:32 +00:00
```diff
namespace App\Repository;
2018-05-04 22:30:32 +00:00
+use App\Entity\Post;
use Doctrine\ORM\EntityRepository;
2018-05-04 22:30:32 +00:00
-final class PostRepository extends EntityRepository
+final class PostRepository
{
+ /**
+ * @var \Doctrine\ORM\EntityRepository
+ */
+ private $repository;
+ public function __construct(\Doctrine\ORM\EntityManager $entityManager)
+ {
+ $this->repository = $entityManager->getRepository(\App\Entity\Post::class);
+ }
}
2018-07-31 12:50:39 +00:00
```
<br>
2018-08-12 18:34:27 +00:00
## StaticCall
### `StaticCallToFunctionRector`
- class: `Rector\Rector\StaticCall\StaticCallToFunctionRector`
Turns static call to function call.
```yaml
services:
Rector\Rector\StaticCall\StaticCallToFunctionRector:
$staticCallToFunction:
OldClass:
oldMethod: new_function
2018-08-12 18:34:27 +00:00
```
```diff
-OldClass::oldMethod("args");
+new_function("args");
```
<br>
2018-08-01 20:09:34 +00:00
## Typehint
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
### `ReturnTypehintRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Typehint\ReturnTypehintRector`
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
Changes defined return typehint of method and class.
```yaml
services:
Rector\Rector\Typehint\ReturnTypehintRector:
SomeClass:
getData: array
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
2018-08-01 20:09:34 +00:00
class SomeClass
{
- public getData();
+ public getData(): array;
}
```
<br>
2018-08-01 20:09:34 +00:00
### `ParentTypehintedArgumentRector`
- class: `Rector\Rector\Typehint\ParentTypehintedArgumentRector`
Changes defined parent class typehints.
```yaml
services:
Rector\Rector\Typehint\ParentTypehintedArgumentRector:
SomeInterface:
read:
$content: string
2018-08-01 20:09:34 +00:00
```
```diff
interface SomeInterface
{
public read(string $content);
}
class SomeClass implements SomeInterface
{
2018-08-01 20:09:34 +00:00
- public read($content);
+ public read(string $content);
}
2018-05-04 22:30:32 +00:00
```
<br>
2018-10-21 22:26:45 +00:00
## Visibility
2018-08-01 20:09:34 +00:00
### `ChangeMethodVisibilityRector`
2018-08-01 20:09:34 +00:00
- class: `Rector\Rector\Visibility\ChangeMethodVisibilityRector`
2018-08-01 20:09:34 +00:00
Change visibility of method from parent class.
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Visibility\ChangeMethodVisibilityRector:
FrameworkClass:
someMethod: protected
2018-08-01 20:09:34 +00:00
```
```diff
2018-10-21 22:26:45 +00:00
class FrameworkClass
{
protected someMethod()
{
}
2018-10-21 22:26:45 +00:00
}
2018-08-01 20:09:34 +00:00
2018-10-21 22:26:45 +00:00
class MyClass extends FrameworkClass
{
- public someMethod()
+ protected someMethod()
{
}
2018-10-21 22:26:45 +00:00
}
2018-08-01 20:09:34 +00:00
```
<br>
### `ChangePropertyVisibilityRector`
2018-05-04 22:30:32 +00:00
- class: `Rector\Rector\Visibility\ChangePropertyVisibilityRector`
Change visibility of property from parent class.
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Visibility\ChangePropertyVisibilityRector:
FrameworkClass:
someProperty: protected
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
class FrameworkClass
{
protected $someProperty;
}
2018-07-31 06:38:48 +00:00
class MyClass extends FrameworkClass
{
- public $someProperty;
+ protected $someProperty;
}
2018-07-31 06:38:48 +00:00
```
<br>
### `ChangeConstantVisibilityRector`
- class: `Rector\Rector\Visibility\ChangeConstantVisibilityRector`
2018-05-04 22:30:32 +00:00
Change visibility of constant from parent class.
2018-05-04 22:30:32 +00:00
2018-08-01 20:09:34 +00:00
```yaml
services:
Rector\Rector\Visibility\ChangeConstantVisibilityRector:
ParentObject:
SOME_CONSTANT: protected
2018-08-01 20:09:34 +00:00
```
2018-05-04 22:30:32 +00:00
```diff
class FrameworkClass
{
protected const SOME_CONSTANT = 1;
}
2018-07-31 12:50:39 +00:00
class MyClass extends FrameworkClass
{
- public const SOME_CONSTANT = 1;
+ protected const SOME_CONSTANT = 1;
}
2018-05-04 22:30:32 +00:00
```
<br>