mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-20 06:38:46 +01:00
update FuncNameToStaticCallName to FuncCallToStaticCall (#4080)
This commit is contained in:
parent
4e91b78c7b
commit
3a7d197b34
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
use Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector;
|
||||
use function Rector\SymfonyPhpConfig\inline_value_objects;
|
||||
use Rector\Transform\ValueObject\FuncNameToStaticCallName;
|
||||
use Rector\Transform\ValueObject\FuncCallToStaticCall;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
@ -13,48 +13,48 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services->set(FuncCallToStaticCallRector::class)
|
||||
->call('configure', [[
|
||||
FuncCallToStaticCallRector::FUNC_CALLS_TO_STATIC_CALLS => inline_value_objects([
|
||||
new FuncNameToStaticCallName('array_add', 'Illuminate\Support\Arr', 'add'),
|
||||
new FuncNameToStaticCallName('array_collapse', 'Illuminate\Support\Arr', 'collapse'),
|
||||
new FuncNameToStaticCallName('array_divide', 'Illuminate\Support\Arr', 'divide'),
|
||||
new FuncNameToStaticCallName('array_dot', 'Illuminate\Support\Arr', 'dot'),
|
||||
new FuncNameToStaticCallName('array_except', 'Illuminate\Support\Arr', 'except'),
|
||||
new FuncNameToStaticCallName('array_first', 'Illuminate\Support\Arr', 'first'),
|
||||
new FuncNameToStaticCallName('array_flatten', 'Illuminate\Support\Arr', 'flatten'),
|
||||
new FuncNameToStaticCallName('array_forget', 'Illuminate\Support\Arr', 'forget'),
|
||||
new FuncNameToStaticCallName('array_get', 'Illuminate\Support\Arr', 'get'),
|
||||
new FuncNameToStaticCallName('array_has', 'Illuminate\Support\Arr', 'has'),
|
||||
new FuncNameToStaticCallName('array_last', 'Illuminate\Support\Arr', 'last'),
|
||||
new FuncNameToStaticCallName('array_only', 'Illuminate\Support\Arr', 'only'),
|
||||
new FuncNameToStaticCallName('array_pluck', 'Illuminate\Support\Arr', 'pluck'),
|
||||
new FuncNameToStaticCallName('array_prepend', 'Illuminate\Support\Arr', 'prepend'),
|
||||
new FuncNameToStaticCallName('array_pull', 'Illuminate\Support\Arr', 'pull'),
|
||||
new FuncNameToStaticCallName('array_random', 'Illuminate\Support\Arr', 'random'),
|
||||
new FuncNameToStaticCallName('array_sort', 'Illuminate\Support\Arr', 'sort'),
|
||||
new FuncNameToStaticCallName('array_sort_recursive', 'Illuminate\Support\Arr', 'sortRecursive'),
|
||||
new FuncNameToStaticCallName('array_where', 'Illuminate\Support\Arr', 'where'),
|
||||
new FuncNameToStaticCallName('array_wrap', 'Illuminate\Support\Arr', 'wrap'),
|
||||
new FuncNameToStaticCallName('array_set', 'Illuminate\Support\Arr', 'set'),
|
||||
new FuncNameToStaticCallName('camel_case', 'Illuminate\Support\Str', 'camel'),
|
||||
new FuncNameToStaticCallName('ends_with', 'Illuminate\Support\Str', 'endsWith'),
|
||||
new FuncNameToStaticCallName('kebab_case', 'Illuminate\Support\Str', 'kebab'),
|
||||
new FuncNameToStaticCallName('snake_case', 'Illuminate\Support\Str', 'snake'),
|
||||
new FuncNameToStaticCallName('starts_with', 'Illuminate\Support\Str', 'startsWith'),
|
||||
new FuncNameToStaticCallName('str_after', 'Illuminate\Support\Str', 'after'),
|
||||
new FuncNameToStaticCallName('str_before', 'Illuminate\Support\Str', 'before'),
|
||||
new FuncNameToStaticCallName('str_contains', 'Illuminate\Support\Str', 'contains'),
|
||||
new FuncNameToStaticCallName('str_finish', 'Illuminate\Support\Str', 'finish'),
|
||||
new FuncNameToStaticCallName('str_is', 'Illuminate\Support\Str', 'is'),
|
||||
new FuncNameToStaticCallName('str_limit', 'Illuminate\Support\Str', 'limit'),
|
||||
new FuncNameToStaticCallName('str_plural', 'Illuminate\Support\Str', 'plural'),
|
||||
new FuncNameToStaticCallName('str_random', 'Illuminate\Support\Str', 'random'),
|
||||
new FuncNameToStaticCallName('str_replace_array', 'Illuminate\Support\Str', 'replaceArray'),
|
||||
new FuncNameToStaticCallName('str_replace_first', 'Illuminate\Support\Str', 'replaceFirst'),
|
||||
new FuncNameToStaticCallName('str_replace_last', 'Illuminate\Support\Str', 'replaceLast'),
|
||||
new FuncNameToStaticCallName('str_singular', 'Illuminate\Support\Str', 'singular'),
|
||||
new FuncNameToStaticCallName('str_slug', 'Illuminate\Support\Str', 'slug'),
|
||||
new FuncNameToStaticCallName('str_start', 'Illuminate\Support\Str', 'start'),
|
||||
new FuncNameToStaticCallName('studly_case', 'Illuminate\Support\Str', 'studly'),
|
||||
new FuncNameToStaticCallName('title_case', 'Illuminate\Support\Str', 'title'),
|
||||
new FuncCallToStaticCall('array_add', 'Illuminate\Support\Arr', 'add'),
|
||||
new FuncCallToStaticCall('array_collapse', 'Illuminate\Support\Arr', 'collapse'),
|
||||
new FuncCallToStaticCall('array_divide', 'Illuminate\Support\Arr', 'divide'),
|
||||
new FuncCallToStaticCall('array_dot', 'Illuminate\Support\Arr', 'dot'),
|
||||
new FuncCallToStaticCall('array_except', 'Illuminate\Support\Arr', 'except'),
|
||||
new FuncCallToStaticCall('array_first', 'Illuminate\Support\Arr', 'first'),
|
||||
new FuncCallToStaticCall('array_flatten', 'Illuminate\Support\Arr', 'flatten'),
|
||||
new FuncCallToStaticCall('array_forget', 'Illuminate\Support\Arr', 'forget'),
|
||||
new FuncCallToStaticCall('array_get', 'Illuminate\Support\Arr', 'get'),
|
||||
new FuncCallToStaticCall('array_has', 'Illuminate\Support\Arr', 'has'),
|
||||
new FuncCallToStaticCall('array_last', 'Illuminate\Support\Arr', 'last'),
|
||||
new FuncCallToStaticCall('array_only', 'Illuminate\Support\Arr', 'only'),
|
||||
new FuncCallToStaticCall('array_pluck', 'Illuminate\Support\Arr', 'pluck'),
|
||||
new FuncCallToStaticCall('array_prepend', 'Illuminate\Support\Arr', 'prepend'),
|
||||
new FuncCallToStaticCall('array_pull', 'Illuminate\Support\Arr', 'pull'),
|
||||
new FuncCallToStaticCall('array_random', 'Illuminate\Support\Arr', 'random'),
|
||||
new FuncCallToStaticCall('array_sort', 'Illuminate\Support\Arr', 'sort'),
|
||||
new FuncCallToStaticCall('array_sort_recursive', 'Illuminate\Support\Arr', 'sortRecursive'),
|
||||
new FuncCallToStaticCall('array_where', 'Illuminate\Support\Arr', 'where'),
|
||||
new FuncCallToStaticCall('array_wrap', 'Illuminate\Support\Arr', 'wrap'),
|
||||
new FuncCallToStaticCall('array_set', 'Illuminate\Support\Arr', 'set'),
|
||||
new FuncCallToStaticCall('camel_case', 'Illuminate\Support\Str', 'camel'),
|
||||
new FuncCallToStaticCall('ends_with', 'Illuminate\Support\Str', 'endsWith'),
|
||||
new FuncCallToStaticCall('kebab_case', 'Illuminate\Support\Str', 'kebab'),
|
||||
new FuncCallToStaticCall('snake_case', 'Illuminate\Support\Str', 'snake'),
|
||||
new FuncCallToStaticCall('starts_with', 'Illuminate\Support\Str', 'startsWith'),
|
||||
new FuncCallToStaticCall('str_after', 'Illuminate\Support\Str', 'after'),
|
||||
new FuncCallToStaticCall('str_before', 'Illuminate\Support\Str', 'before'),
|
||||
new FuncCallToStaticCall('str_contains', 'Illuminate\Support\Str', 'contains'),
|
||||
new FuncCallToStaticCall('str_finish', 'Illuminate\Support\Str', 'finish'),
|
||||
new FuncCallToStaticCall('str_is', 'Illuminate\Support\Str', 'is'),
|
||||
new FuncCallToStaticCall('str_limit', 'Illuminate\Support\Str', 'limit'),
|
||||
new FuncCallToStaticCall('str_plural', 'Illuminate\Support\Str', 'plural'),
|
||||
new FuncCallToStaticCall('str_random', 'Illuminate\Support\Str', 'random'),
|
||||
new FuncCallToStaticCall('str_replace_array', 'Illuminate\Support\Str', 'replaceArray'),
|
||||
new FuncCallToStaticCall('str_replace_first', 'Illuminate\Support\Str', 'replaceFirst'),
|
||||
new FuncCallToStaticCall('str_replace_last', 'Illuminate\Support\Str', 'replaceLast'),
|
||||
new FuncCallToStaticCall('str_singular', 'Illuminate\Support\Str', 'singular'),
|
||||
new FuncCallToStaticCall('str_slug', 'Illuminate\Support\Str', 'slug'),
|
||||
new FuncCallToStaticCall('str_start', 'Illuminate\Support\Str', 'start'),
|
||||
new FuncCallToStaticCall('studly_case', 'Illuminate\Support\Str', 'studly'),
|
||||
new FuncCallToStaticCall('title_case', 'Illuminate\Support\Str', 'title'),
|
||||
]),
|
||||
]]);
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ use Rector\Nette\Rector\Identical\StartsWithFunctionToNetteUtilsStringsRector;
|
||||
use Rector\Nette\Rector\NotIdentical\StrposToStringsContainsRector;
|
||||
use Rector\NetteUtilsCodeQuality\Rector\LNumber\ReplaceTimeNumberWithDateTimeConstantRector;
|
||||
use function Rector\SymfonyPhpConfig\inline_value_objects;
|
||||
use Rector\Transform\ValueObject\FuncNameToStaticCallName;
|
||||
use Rector\Transform\ValueObject\FuncCallToStaticCall;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
# @see https://www.tomasvotruba.cz/blog/2018/07/30/hidden-gems-of-php-packages-nette-utils
|
||||
@ -23,9 +23,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services->set(FuncCallToStaticCallRector::class)
|
||||
->call('configure', [[
|
||||
FuncCallToStaticCallRector::FUNC_CALLS_TO_STATIC_CALLS => inline_value_objects([
|
||||
new FuncNameToStaticCallName('file_get_contents', 'Nette\Utils\FileSystem', 'read'),
|
||||
new FuncNameToStaticCallName('unlink', 'Nette\Utils\FileSystem', 'delete'),
|
||||
new FuncNameToStaticCallName('rmdir', 'Nette\Utils\FileSystem', 'delete'),
|
||||
new FuncCallToStaticCall('file_get_contents', 'Nette\Utils\FileSystem', 'read'),
|
||||
new FuncCallToStaticCall('unlink', 'Nette\Utils\FileSystem', 'delete'),
|
||||
new FuncCallToStaticCall('rmdir', 'Nette\Utils\FileSystem', 'delete'),
|
||||
]),
|
||||
]]);
|
||||
|
||||
|
@ -5160,7 +5160,7 @@ return function (ContainerConfigurator $containerConfigurator) : void {
|
||||
$services->set(FuncCallToStaticCallRector::class)
|
||||
->call('configure', [[
|
||||
FuncCallToStaticCallRector::FUNC_CALLS_TO_STATIC_CALLS => [
|
||||
\Rector\SymfonyPhpConfig\inline_value_object(new Rector\Transform\ValueObject\FuncNameToStaticCallName('view', 'SomeStaticClass', 'render'))]
|
||||
\Rector\SymfonyPhpConfig\inline_value_object(new Rector\Transform\ValueObject\FuncCallToStaticCall('view', 'SomeStaticClass', 'render'))]
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
@ -10,7 +10,8 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Transform\ValueObject\FuncNameToStaticCallName;
|
||||
use Rector\Transform\ValueObject\FuncCallToStaticCall;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @see \Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector\FuncCallToStaticCallRectorTest
|
||||
@ -23,9 +24,9 @@ final class FuncCallToStaticCallRector extends AbstractRector implements Configu
|
||||
public const FUNC_CALLS_TO_STATIC_CALLS = 'func_calls_to_static_calls';
|
||||
|
||||
/**
|
||||
* @var FuncNameToStaticCallName[]
|
||||
* @var FuncCallToStaticCall[]
|
||||
*/
|
||||
private $funcNameToStaticCallNames = [];
|
||||
private $funcCallsToStaticCalls = [];
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
@ -35,7 +36,7 @@ final class FuncCallToStaticCallRector extends AbstractRector implements Configu
|
||||
'SomeClass::render("...", []);',
|
||||
[
|
||||
self::FUNC_CALLS_TO_STATIC_CALLS => [
|
||||
new FuncNameToStaticCallName('view', 'SomeStaticClass', 'render'),
|
||||
new FuncCallToStaticCall('view', 'SomeStaticClass', 'render'),
|
||||
],
|
||||
]
|
||||
),
|
||||
@ -55,14 +56,14 @@ final class FuncCallToStaticCallRector extends AbstractRector implements Configu
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($this->funcNameToStaticCallNames as $funcNameToStaticCallName) {
|
||||
if (! $this->isName($node, $funcNameToStaticCallName->getOldFuncName())) {
|
||||
foreach ($this->funcCallsToStaticCalls as $funcCallsToStaticCall) {
|
||||
if (! $this->isName($node, $funcCallsToStaticCall->getOldFuncName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->createStaticCall(
|
||||
$funcNameToStaticCallName->getNewClassName(),
|
||||
$funcNameToStaticCallName->getNewMethodName(),
|
||||
$funcCallsToStaticCall->getNewClassName(),
|
||||
$funcCallsToStaticCall->getNewMethodName(),
|
||||
$node->args
|
||||
);
|
||||
}
|
||||
@ -72,6 +73,8 @@ final class FuncCallToStaticCallRector extends AbstractRector implements Configu
|
||||
|
||||
public function configure(array $configuration): void
|
||||
{
|
||||
$this->funcNameToStaticCallNames = $configuration[self::FUNC_CALLS_TO_STATIC_CALLS] ?? [];
|
||||
$funcCallsToStaticCalls = $configuration[self::FUNC_CALLS_TO_STATIC_CALLS] ?? [];
|
||||
Assert::allIsInstanceOf($funcCallsToStaticCalls, FuncCallToStaticCall::class);
|
||||
$this->funcCallsToStaticCalls = $funcCallsToStaticCalls;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector;
|
||||
use Iterator;
|
||||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector;
|
||||
use Rector\Transform\ValueObject\FuncNameToStaticCallName;
|
||||
use Rector\Transform\ValueObject\FuncCallToStaticCall;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class FuncCallToStaticCallRectorTest extends AbstractRectorTestCase
|
||||
@ -33,8 +33,8 @@ final class FuncCallToStaticCallRectorTest extends AbstractRectorTestCase
|
||||
return [
|
||||
FuncCallToStaticCallRector::class => [
|
||||
FuncCallToStaticCallRector::FUNC_CALLS_TO_STATIC_CALLS => [
|
||||
new FuncNameToStaticCallName('view', 'SomeStaticClass', 'render'),
|
||||
new FuncNameToStaticCallName('SomeNamespaced\view', 'AnotherStaticClass', 'render'),
|
||||
new FuncCallToStaticCall('view', 'SomeStaticClass', 'render'),
|
||||
new FuncCallToStaticCall('SomeNamespaced\view', 'AnotherStaticClass', 'render'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\Transform\ValueObject;
|
||||
|
||||
final class FuncNameToStaticCallName
|
||||
final class FuncCallToStaticCall
|
||||
{
|
||||
/**
|
||||
* @var string
|
Loading…
x
Reference in New Issue
Block a user