Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 115 additions & 7 deletions docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# All 490 Rectors Overview
# All 494 Rectors Overview

- [Projects](#projects)
- [General](#general)
Expand All @@ -11,7 +11,7 @@
- [CakePHP](#cakephp) (5)
- [Celebrity](#celebrity) (3)
- [CodeQuality](#codequality) (53)
- [CodingStyle](#codingstyle) (30)
- [CodingStyle](#codingstyle) (31)
- [DeadCode](#deadcode) (40)
- [Doctrine](#doctrine) (16)
- [DoctrineCodeQuality](#doctrinecodequality) (2)
Expand All @@ -26,7 +26,7 @@
- [MysqlToMysqli](#mysqltomysqli) (4)
- [Naming](#naming) (1)
- [Nette](#nette) (12)
- [NetteKdyby](#nettekdyby) (2)
- [NetteKdyby](#nettekdyby) (4)
- [NetteTesterToPHPUnit](#nettetestertophpunit) (3)
- [NetteToSymfony](#nettetosymfony) (9)
- [Order](#order) (3)
Expand All @@ -51,7 +51,7 @@
- [PhpDeglobalize](#phpdeglobalize) (1)
- [PhpSpecToPHPUnit](#phpspectophpunit) (7)
- [Polyfill](#polyfill) (2)
- [Privatization](#privatization) (6)
- [Privatization](#privatization) (7)
- [Refactoring](#refactoring) (2)
- [RemovingStatic](#removingstatic) (4)
- [Renaming](#renaming) (10)
Expand Down Expand Up @@ -2116,6 +2116,30 @@ Prefer quote that are not inside the string

<br>

### `UnderscoreToPascalCaseVariableAndPropertyNameRector`

- class: [`Rector\CodingStyle\Rector\Variable\UnderscoreToPascalCaseVariableAndPropertyNameRector`](/../master/rules/coding-style/src/Rector/Variable/UnderscoreToPascalCaseVariableAndPropertyNameRector.php)
- [test fixtures](/../master/rules/coding-style/tests/Rector/Variable/UnderscoreToPascalCaseVariableAndPropertyNameRector/Fixture)

Change under_score names to pascalCase

```diff
final class SomeClass
{
- public function run($a_b)
+ public function run($aB)
{
- $some_value = 5;
+ $someValue = 5;

- $this->run($a_b);
+ $this->run($aB);
}
}
```

<br>

### `UseIncrementAssignRector`

- class: [`Rector\CodingStyle\Rector\Assign\UseIncrementAssignRector`](/../master/rules/coding-style/src/Rector/Assign/UseIncrementAssignRector.php)
Expand Down Expand Up @@ -4606,7 +4630,6 @@ Change EventSubscriber from Kdyby to Contributte
return [
- Application::class . '::onShutdown',
+ ShutdownEvent::class => 'onShutdown',
CustomService::class . '::onCopy' => 'onCustomCopy',
];
}

Expand All @@ -4617,9 +4640,69 @@ Change EventSubscriber from Kdyby to Contributte
$presenterName = $presenter->getName();
// ...
}
}
```

<br>

### `ReplaceEventManagerWithEventSubscriberRector`

- class: [`Rector\NetteKdyby\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector`](/../master/rules/nette-kdyby/src/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector.php)
- [test fixtures](/../master/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Fixture)

Change Kdyby EventManager to EventDispatcher

```diff
use Kdyby\Events\EventManager;

final class SomeClass
{
/**
* @var EventManager
*/
private $eventManager;

public function __construct(EventManager $eventManager)
{
$this->eventManager = eventManager;
}

public function run()
{
$key = '2000';
- $this->eventManager->dispatchEvent(static::class . '::onCopy', new EventArgsList([$this, $key]));
+ $this->eventManager->dispatch(new SomeClassCopyEvent($this, $key));
}
}
```

<br>

public function onCustomCopy()
### `ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector`

- class: [`Rector\NetteKdyby\Rector\ClassMethod\ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector`](/../master/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector.php)
- [test fixtures](/../master/rules/nette-kdyby/tests/Rector/ClassMethod/ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector/Fixture)

Change getSubscribedEvents() from on magic property, to Event class

```diff
use Kdyby\Events\Subscriber;

final class ActionLogEventSubscriber implements Subscriber
{
public function getSubscribedEvents(): array
{
return [
- AlbumService::class . '::onApprove' => 'onAlbumApprove',
+ AlbumServiceApproveEvent::class => 'onAlbumApprove',
];
}

- public function onAlbumApprove(Album $album, int $adminId): void
+ public function onAlbumApprove(AlbumServiceApproveEventAlbum $albumServiceApproveEventAlbum): void
{
+ $album = $albumServiceApproveEventAlbum->getAlbum();
$album->play();
}
}
```
Expand All @@ -4637,7 +4720,13 @@ Change $onProperty magic call with event disptacher and class dispatch
final class FileManager
{
- public $onUpload;
-
+ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

+ public function __construct(EventDispatcherInterface $eventDispatcher)
+ {
+ $this->eventDispatcher = $eventDispatcher;
+ }
+
public function run(User $user)
{
- $this->onUpload($user);
Expand Down Expand Up @@ -8345,6 +8434,25 @@ Change local property used in single method to local variable

<br>

### `PrivatizeFinalClassMethodRector`

- class: [`Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector`](/../master/rules/privatization/src/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php)
- [test fixtures](/../master/rules/privatization/tests/Rector/ClassMethod/PrivatizeFinalClassMethodRector/Fixture)

Change protected class method to private if possible

```diff
final class SomeClass
{
- protected function someMethod()
+ private function someMethod()
{
}
}
```

<br>

### `PrivatizeFinalClassPropertyRector`

- class: [`Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector`](/../master/rules/privatization/src/Rector/Property/PrivatizeFinalClassPropertyRector.php)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\NetteKdyby\NodeManipulator;

use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
Expand All @@ -12,6 +13,8 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\CodingStyle\Naming\ClassNaming;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\NetteKdyby\ContributeEventClassResolver;

final class SubscriberMethodArgumentToContributteEventObjectManipulator
Expand All @@ -26,12 +29,26 @@ final class SubscriberMethodArgumentToContributteEventObjectManipulator
*/
private $contributeEventClassResolver;

/**
* @var BetterNodeFinder
*/
private $betterNodeFinder;

/**
* @var BetterStandardPrinter
*/
private $betterStandardPrinter;

public function __construct(
BetterNodeFinder $betterNodeFinder,
ClassNaming $classNaming,
ContributeEventClassResolver $contributeEventClassResolver
ContributeEventClassResolver $contributeEventClassResolver,
BetterStandardPrinter $betterStandardPrinter
) {
$this->classNaming = $classNaming;
$this->contributeEventClassResolver = $contributeEventClassResolver;
$this->betterNodeFinder = $betterNodeFinder;
$this->betterStandardPrinter = $betterStandardPrinter;
}

/**
Expand All @@ -44,8 +61,12 @@ public function change(array $classMethodsByEventClass): void

$this->changeClassParamToEventClass($eventClass, $classMethod);

// move params
// move params to getter on event
foreach ($oldParams as $oldParam) {
if (! $this->isParamUsedInClassMethodBody($classMethod, $oldParam)) {
continue;
}

$eventGetterToVariableAssign = $this->createEventGetterToVariableMethodCall($eventClass, $oldParam);
$expression = new Expression($eventGetterToVariableAssign);

Expand All @@ -54,6 +75,19 @@ public function change(array $classMethodsByEventClass): void
}
}

private function isParamUsedInClassMethodBody(ClassMethod $classMethod, Param $param): bool
{
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) use (
$param
) {
if (! $node instanceof Variable) {
return false;
}

return $this->betterStandardPrinter->areNodesEqual($node, $param->var);
});
}

private function changeClassParamToEventClass(string $eventClass, ClassMethod $classMethod): void
{
/** @var ClassMethod $classMethod */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function getSubscribedEvents(): array

public function onAlbumApprove(Album $album, int $adminId): void
{
$album->play();
}
}
PHP
Expand All @@ -85,7 +86,7 @@ public function getSubscribedEvents(): array
public function onAlbumApprove(AlbumServiceApproveEventAlbum $albumServiceApproveEventAlbum): void
{
$album = $albumServiceApproveEventAlbum->getAlbum();
$adminId = $albumServiceApproveEventAlbum->getAdminId();
$album->play();
}
}
PHP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class ActionLogEventSubscriber implements Subscriber

public function onTomatoBuy(Tomato $tomato, int $adminId): void
{
$tomato->unwrap();
}
}

Expand All @@ -41,8 +42,8 @@ final class ActionLogEventSubscriber implements Subscriber

public function onTomatoBuy(\Rector\NetteKdyby\Tests\Rector\ClassMethod\ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector\Source\Event\VegetableMarketTomatoBuyEvent $vegetableMarketTomatoBuyEvent): void
{
$adminId = $vegetableMarketTomatoBuyEvent->getAdminId();
$tomato = $vegetableMarketTomatoBuyEvent->getTomato();
$tomato->unwrap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

final class Tomato
{

public function unwrap()
{
}
}