Skip to content

Commit

Permalink
[DX] Autowire commands explicitly (#4118)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 8, 2023
1 parent 6c3eb86 commit 8db9a6f
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 338 deletions.
248 changes: 9 additions & 239 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 383 Rules Overview
# 377 Rules Overview

<br>

Expand All @@ -12,16 +12,14 @@

- [DeadCode](#deadcode) (44)

- [DependencyInjection](#dependencyinjection) (2)
- [DependencyInjection](#dependencyinjection) (1)

- [EarlyReturn](#earlyreturn) (10)

- [MysqlToMysqli](#mysqltomysqli) (4)

- [Naming](#naming) (6)

- [PSR4](#psr4) (1)

- [Php52](#php52) (2)

- [Php53](#php53) (3)
Expand All @@ -44,21 +42,21 @@

- [Php80](#php80) (18)

- [Php81](#php81) (12)
- [Php81](#php81) (11)

- [Php82](#php82) (3)

- [Privatization](#privatization) (5)
- [Privatization](#privatization) (4)

- [Removing](#removing) (6)

- [RemovingStatic](#removingstatic) (1)

- [Renaming](#renaming) (10)

- [Strict](#strict) (6)
- [Strict](#strict) (5)

- [Transform](#transform) (27)
- [Transform](#transform) (26)

- [TypeDeclaration](#typedeclaration) (40)

Expand Down Expand Up @@ -651,30 +649,13 @@ Change multiple null compares to ?? queue

Replaces static::* access to private constants with self::*

:wrench: **configure it!**

- class: [`Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector`](../rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php)

```php
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ConvertStaticPrivateConstantToSelfRector::class, [
ConvertStaticPrivateConstantToSelfRector::ENABLE_FOR_NON_FINAL_CLASSES => false,
]);
};
```


```diff
final class Foo {
final class Foo
{
private const BAR = 'bar';

public function run()
{
- $bar = static::BAR;
Expand Down Expand Up @@ -2971,27 +2952,8 @@ Remove unused parent call with no parent class

Remove unneeded PHP_VERSION_ID conditional checks

:wrench: **configure it!**

- class: [`Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector`](../rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php)

```php
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(RemovePhpVersionIdCheckRector::class, [
80000,
]);
};
```


```diff
class SomeClass
{
Expand Down Expand Up @@ -3155,27 +3117,8 @@ Remove unused private method

Remove unused private properties

:wrench: **configure it!**

- class: [`Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector`](../rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php)

```php
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(RemoveUnusedPrivatePropertyRector::class, [
RemoveUnusedPrivatePropertyRector::REMOVE_ASSIGN_SIDE_EFFECT => true,
]);
};
```


```diff
class SomeClass
{
Expand Down Expand Up @@ -3369,31 +3312,6 @@ Remove php version checks if they are passed

## DependencyInjection

### ActionInjectionToConstructorInjectionRector

Turns action injection in Controllers to constructor injection

- class: [`Rector\DependencyInjection\Rector\Class_\ActionInjectionToConstructorInjectionRector`](../rules/DependencyInjection/Rector/Class_/ActionInjectionToConstructorInjectionRector.php)

```diff
final class SomeController
{
- public function default(ProductRepository $productRepository)
+ public function __construct(
+ private ProductRepository $productRepository
+ ) {
+ }
+
+ public function default()
{
- $products = $productRepository->fetchAll();
+ $products = $this->productRepository->fetchAll();
}
}
```

<br>

### AddMethodParentCallRector

Add method parent call, in case new parent method is added
Expand Down Expand Up @@ -3918,36 +3836,6 @@ Rename variable to match new ClassType

<br>

## PSR4

### MultipleClassFileToPsr4ClassesRector

Change multiple classes in one file to standalone PSR-4 classes.

- class: [`Rector\PSR4\Rector\Namespace_\MultipleClassFileToPsr4ClassesRector`](../rules/PSR4/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector.php)

```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>

## Php52

### ContinueToBreakInSwitchRector
Expand Down Expand Up @@ -5797,26 +5685,6 @@ Add `Stringable` interface to classes with `__toString()` method

## Php81

### ConstantListClassToEnumRector

Upgrade constant list classes to full blown enum

- class: [`Rector\Php81\Rector\Class_\ConstantListClassToEnumRector`](../rules/Php81/Rector/Class_/ConstantListClassToEnumRector.php)

```diff
-class Direction
+enum Direction
{
- public const LEFT = 'left';
+ case LEFT;

- public const RIGHT = 'right';
+ case RIGHT;
}
```

<br>

### FinalizePublicClassConstantRector

Add final to constants that does not have children
Expand Down Expand Up @@ -6092,34 +5960,6 @@ Change deprecated utf8_decode and utf8_encode to mb_convert_encoding

## Privatization

### ChangeGlobalVariablesToPropertiesRector

Change global `$variables` to private properties

- class: [`Rector\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector`](../rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php)

```diff
class SomeClass
{
+ private $variable;
public function go()
{
- global $variable;
- $variable = 5;
+ $this->variable = 5;
}

public function run()
{
- global $variable;
- var_dump($variable);
+ var_dump($this->variable);
}
}
```

<br>

### FinalizeClassesWithoutChildrenRector

Finalize every class that has no children
Expand Down Expand Up @@ -6811,27 +6651,6 @@ return static function (RectorConfig $rectorConfig): void {

## Strict

### AddConstructorParentCallRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\Classes\RequireParentConstructCallRule"

- class: [`Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector`](../rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php)

```diff
class SunshineCommand extends ParentClassWithConstructor
{
- public function __construct()
+ public function __construct(ParentDependency $parentDependency)
{
$value = 5;
+
+ parent::__construct($parentDependency);
}
}
```

<br>

### BooleanInBooleanNotRuleFixerRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule"
Expand Down Expand Up @@ -7547,55 +7366,6 @@ return static function (RectorConfig $rectorConfig): void {

<br>

### NewToConstructorInjectionRector

Change defined new type to constructor injection

:wrench: **configure it!**

- class: [`Rector\Transform\Rector\New_\NewToConstructorInjectionRector`](../rules/Transform/Rector/New_/NewToConstructorInjectionRector.php)

```php
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Transform\Rector\New_\NewToConstructorInjectionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(NewToConstructorInjectionRector::class, [
'Validator',
]);
};
```


```diff
class SomeClass
{
+ /**
+ * @var Validator
+ */
+ private $validator;
+
+ public function __construct(Validator $validator)
+ {
+ $this->validator = $validator;
+ }
+
public function run()
{
- $validator = new Validator();
- $validator->validate(1000);
+ $this->validator->validate(1000);
}
}
```

<br>

### NewToStaticCallRector

Change new Object to static call
Expand Down
2 changes: 2 additions & 0 deletions config/set/code-quality.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
use Rector\Config\RectorConfig;
use Rector\Php52\Rector\Property\VarToPublicPropertyRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\RemovingStatic\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;

Expand Down Expand Up @@ -188,5 +189,6 @@
CleanupUnneededNullsafeOperatorRector::class,
DisallowedEmptyRuleFixerRector::class,
ConvertStaticPrivateConstantToSelfRector::class,
LocallyCalledStaticMethodToNonStaticRector::class,
]);
};
2 changes: 2 additions & 0 deletions config/set/dead-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
use Rector\DeadCode\Rector\For_\RemoveDeadContinueRector;
Expand Down Expand Up @@ -95,5 +96,6 @@

RemoveAlwaysTrueIfConditionRector::class,
RemoveDeadZeroAndOneOperationRector::class,
RemovePhpVersionIdCheckRector::class,
]);
};
Loading

0 comments on commit 8db9a6f

Please sign in to comment.