[Transform] Move StaticCallToMethodCallRector to Transform (#4084)

* drop MessageAsArrayRector, as only rule in guzzle

* [Transform] Move StaticCallToMethodCallRector to Transform
This commit is contained in:
Tomas Votruba 2020-08-31 02:26:25 +02:00 committed by GitHub
parent df6e083324
commit 082f1c6294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 92 additions and 125 deletions

View File

@ -149,8 +149,7 @@
"Rector\\NetteUtilsCodeQuality\\": "rules/nette-utils-code-quality/src",
"Rector\\NetteCodeQuality\\": "rules/nette-code-quality/src",
"Rector\\Downgrade\\": "rules/downgrade/src",
"Rector\\SymfonyPhpConfig\\": "rules/symfony-php-config/src",
"Rector\\Injection\\": "rules/injection/src"
"Rector\\SymfonyPhpConfig\\": "rules/symfony-php-config/src"
},
"files": [
"rules/symfony-php-config/functions/functions.php"
@ -234,7 +233,6 @@
"Rector\\NetteCodeQuality\\Tests\\": "rules/nette-code-quality/tests",
"Rector\\Downgrade\\Tests\\": "rules/downgrade/tests",
"Rector\\SymfonyPhpConfig\\Tests\\": "rules/symfony-php-config/tests",
"Rector\\Injection\\Tests\\": "rules/injection/tests",
"Rector\\PHPStanStaticTypeMapper\\Tests\\": "packages/phpstan-static-type-mapper/tests"
},
"classmap": [

View File

@ -7,8 +7,6 @@ use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Generic\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
use Rector\Generic\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
use Rector\Generic\ValueObject\ReplacedArgument;
use Rector\Injection\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Injection\ValueObject\StaticCallToMethodCall;
use Rector\Nette\Rector\MethodCall\AddDatePickerToDateControlRector;
use Rector\Nette\Rector\MethodCall\BuilderExpandToHelperExpandRector;
use Rector\Nette\Rector\MethodCall\GetConfigWithDefaultsArgumentToArrayMergeInCompilerExtensionRector;
@ -21,6 +19,8 @@ use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\ClassConstantRename;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {

View File

@ -1,4 +1,4 @@
# All 567 Rectors Overview
# All 566 Rectors Overview
- [Projects](#projects)
---
@ -19,8 +19,6 @@
- [DynamicTypeAnalysis](#dynamictypeanalysis) (3)
- [FileSystemRector](#filesystemrector) (1)
- [Generic](#generic) (39)
- [Guzzle](#guzzle) (1)
- [Injection](#injection) (1)
- [JMS](#jms) (2)
- [Laravel](#laravel) (5)
- [Legacy](#legacy) (4)
@ -69,7 +67,7 @@
- [SymfonyCodeQuality](#symfonycodequality) (1)
- [SymfonyPHPUnit](#symfonyphpunit) (1)
- [SymfonyPhpConfig](#symfonyphpconfig) (2)
- [Transform](#transform) (9)
- [Transform](#transform) (10)
- [Twig](#twig) (1)
- [TypeDeclaration](#typedeclaration) (9)
@ -5983,76 +5981,6 @@ return function (ContainerConfigurator $containerConfigurator) : void {
<br><br>
## Guzzle
### `MessageAsArrayRector`
- class: [`Rector\Guzzle\Rector\MethodCall\MessageAsArrayRector`](/../master/rules/guzzle/src/Rector/MethodCall/MessageAsArrayRector.php)
- [test fixtures](/../master/rules/guzzle/tests/Rector/MethodCall/MessageAsArrayRector/Fixture)
Changes getMessage(..., true) to `getMessageAsArray()`
```diff
/** @var GuzzleHttp\Message\MessageInterface */
-$value = $message->getMessage('key', true);
+$value = $message->getMessageAsArray('key');
```
<br><br>
## Injection
### `StaticCallToMethodCallRector`
- class: [`Rector\Injection\Rector\StaticCall\StaticCallToMethodCallRector`](/../master/rules/injection/src/Rector/StaticCall/StaticCallToMethodCallRector.php)
- [test fixtures](/../master/rules/injection/tests/Rector/StaticCall/StaticCallToMethodCallRector/Fixture)
Change static call to service method via constructor injection
```php
<?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Injection\Rector\StaticCall\StaticCallToMethodCallRector;
return function (ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->set(StaticCallToMethodCallRector::class)
->call('configure', [[
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => [
\Rector\SymfonyPhpConfig\inline_value_object(new Rector\Injection\ValueObject\StaticCallToMethodCall('Nette\Utils\FileSystem', 'write', 'Symplify\SmartFileSystem\SmartFileSystem', 'dumpFile'))]
]]);
};
```
```diff
-use Nette\Utils\FileSystem;
+use Symplify\SmartFileSystem\SmartFileSystem;
class SomeClass
{
+ /**
+ * @var SmartFileSystem
+ */
+ private $smartFileSystem;
+
+ public function __construct(SmartFileSystem $smartFileSystem)
+ {
+ $this->smartFileSystem = $smartFileSystem;
+ }
+
public function run()
{
- return FileSystem::write('file', 'content');
+ return $this->smartFileSystem->dumpFile('file', 'content');
}
}
```
<br><br>
## JMS
### `RemoveJmsInjectParamsAnnotationRector`
@ -14354,6 +14282,57 @@ return function (ContainerConfigurator $containerConfigurator) : void {
<br><br>
### `StaticCallToMethodCallRector`
- class: [`Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector`](/../master/rules/transform/src/Rector/StaticCall/StaticCallToMethodCallRector.php)
- [test fixtures](/../master/rules/transform/tests/Rector/StaticCall/StaticCallToMethodCallRector/Fixture)
Change static call to service method via constructor injection
```php
<?php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
return function (ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->set(StaticCallToMethodCallRector::class)
->call('configure', [[
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => [
\Rector\SymfonyPhpConfig\inline_value_object(new Rector\Transform\ValueObject\StaticCallToMethodCall('Nette\Utils\FileSystem', 'write', 'Symplify\SmartFileSystem\SmartFileSystem', 'dumpFile'))]
]]);
};
```
```diff
-use Nette\Utils\FileSystem;
+use Symplify\SmartFileSystem\SmartFileSystem;
class SomeClass
{
+ /**
+ * @var SmartFileSystem
+ */
+ private $smartFileSystem;
+
+ public function __construct(SmartFileSystem $smartFileSystem)
+ {
+ $this->smartFileSystem = $smartFileSystem;
+ }
+
public function run()
{
- return FileSystem::write('file', 'content');
+ return $this->smartFileSystem->dumpFile('file', 'content');
}
}
```
<br><br>
## Twig
### `SimpleFunctionAndFilterRector`

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Injection\Rector\StaticCall;
namespace Rector\Transform\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
@ -14,12 +14,12 @@ use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\Generic\Rector\AbstractToMethodCallRector;
use Rector\Injection\ValueObject\StaticCallToMethodCall;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\StaticCallToMethodCallRectorTest
* @see \Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\StaticCallToMethodCallRectorTest
*/
final class StaticCallToMethodCallRector extends AbstractToMethodCallRector
{
@ -27,7 +27,7 @@ final class StaticCallToMethodCallRector extends AbstractToMethodCallRector
* @api
* @var string
*/
public const STATIC_CALLS_TO_METHOD_CALLS = '$staticCallsToMethodCalls';
public const STATIC_CALLS_TO_METHOD_CALLS = 'static_calls_to_method_calls';
/**
* @var StaticCallToMethodCall[]
@ -126,15 +126,7 @@ PHP
public function configure(array $configuration): void
{
$staticCallsToMethodCalls = $configuration[self::STATIC_CALLS_TO_METHOD_CALLS] ?? [];
$message = sprintf(
'Configuration for "%s" must be in object of "%s". "%s" given',
self::class,
StaticCallToMethodCall::class,
gettype($staticCallsToMethodCalls)
);
Assert::allIsInstanceOf($staticCallsToMethodCalls, StaticCallToMethodCall::class, $message);
Assert::allIsInstanceOf($staticCallsToMethodCalls, StaticCallToMethodCall::class);
$this->staticCallsToMethodCalls = $staticCallsToMethodCalls;
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Injection\ValueObject;
namespace Rector\Transform\ValueObject;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
@ -16,7 +16,7 @@ class SomeClass
-----
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
@ -16,7 +16,7 @@ class InConstructor
-----
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
@ -16,7 +16,7 @@ class InstantMakeInStaticMethod
-----
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;

View File

@ -1,9 +1,9 @@
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
use Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystemMethod;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystemMethod;
class ReUseParentProperty extends ClassWithFileSystemMethod
{
@ -17,10 +17,10 @@ class ReUseParentProperty extends ClassWithFileSystemMethod
-----
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
use Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystemMethod;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystemMethod;
class ReUseParentProperty extends ClassWithFileSystemMethod
{

View File

@ -1,9 +1,9 @@
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
use Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystem;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystem;
class ReUseParentMethod extends ClassWithFileSystem
{
@ -17,10 +17,10 @@ class ReUseParentMethod extends ClassWithFileSystem
-----
<?php
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Fixture;
use Nette\Utils\FileSystem;
use Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystem;
use Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source\ClassWithFileSystem;
class ReUseParentMethod extends ClassWithFileSystem
{

View File

@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector;
use InvalidArgumentException;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Injection\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class InvalidConfigurationTest extends AbstractRectorTestCase

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source;
use Symplify\SmartFileSystem\SmartFileSystem;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\Source;
use Symplify\SmartFileSystem\SmartFileSystem;

View File

@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Rector\Injection\Tests\Rector\StaticCall\StaticCallToMethodCallRector;
namespace Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Injection\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Injection\ValueObject\StaticCallToMethodCall;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Symplify\SmartFileSystem\SmartFileInfo;
final class StaticCallToMethodCallRectorTest extends AbstractRectorTestCase
@ -26,22 +26,20 @@ final class StaticCallToMethodCallRectorTest extends AbstractRectorTestCase
}
/**
* @return StaticCallToMethodCall[][][]
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
{
$configuration = [
new StaticCallToMethodCall(
'Nette\Utils\FileSystem',
'write',
'Symplify\SmartFileSystem\SmartFileSystem',
'dumpFile'
),
];
return [
StaticCallToMethodCallRector::class => [
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => $configuration,
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => [
new StaticCallToMethodCall(
'Nette\Utils\FileSystem',
'write',
'Symplify\SmartFileSystem\SmartFileSystem',
'dumpFile'
),
],
],
];
}