2020-07-18 20:26:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-07-29 02:27:21 +02:00
|
|
|
use PhpParser\Node\Expr\MethodCall;
|
2020-07-18 20:26:57 +02:00
|
|
|
use Rector\Core\Configuration\Option;
|
2020-07-29 02:27:21 +02:00
|
|
|
use Rector\RectorGenerator\ValueObject\RecipeOption;
|
2020-07-18 20:26:57 +02:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
|
|
|
|
2020-07-29 02:27:21 +02:00
|
|
|
// run "bin/rector create" to create a new Rector + tests from this config
|
2020-07-18 20:26:57 +02:00
|
|
|
return static function (ContainerConfigurator $containerConfigurator): void {
|
|
|
|
$parameters = $containerConfigurator->parameters();
|
|
|
|
|
|
|
|
$parameters->set(Option::RECTOR_RECIPE, [
|
2020-07-29 02:27:21 +02:00
|
|
|
RecipeOption::PACKAGE => 'Nette',
|
|
|
|
RecipeOption::NAME => 'TranslateClassMethodToVariadicsRector',
|
|
|
|
RecipeOption::NODE_TYPES => [
|
|
|
|
MethodCall::class,
|
2020-07-18 20:26:57 +02:00
|
|
|
],
|
2020-07-29 02:27:21 +02:00
|
|
|
RecipeOption::DESCRIPTION => 'Change translate() method call 2nd arg to variadic',
|
|
|
|
RecipeOption::CODE_BEFORE => <<<'CODE_SAMPLE'
|
2020-07-18 20:26:57 +02:00
|
|
|
<?php
|
|
|
|
|
2020-07-29 02:27:21 +02:00
|
|
|
use Nette\Localization\ITranslator;
|
2020-07-18 20:26:57 +02:00
|
|
|
|
2020-07-29 02:27:21 +02:00
|
|
|
final class SomeClass implements ITranslator
|
2020-07-18 20:26:57 +02:00
|
|
|
{
|
2020-07-29 02:27:21 +02:00
|
|
|
public function translate($message, $count = null)
|
2020-07-18 20:26:57 +02:00
|
|
|
{
|
2020-07-29 02:27:21 +02:00
|
|
|
return [$message, $count];
|
2020-07-18 20:26:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CODE_SAMPLE,
|
2020-07-29 02:27:21 +02:00
|
|
|
RecipeOption::CODE_AFTER => <<<'CODE_SAMPLE'
|
2020-07-18 20:26:57 +02:00
|
|
|
<?php
|
|
|
|
|
2020-07-29 02:27:21 +02:00
|
|
|
use Nette\Localization\ITranslator;
|
2020-07-18 20:26:57 +02:00
|
|
|
|
2020-07-29 02:27:21 +02:00
|
|
|
final class SomeClass implements ITranslator
|
2020-07-18 20:26:57 +02:00
|
|
|
{
|
2020-07-29 02:27:21 +02:00
|
|
|
public function translate($message, ... $parameters)
|
|
|
|
{
|
|
|
|
$count = $parameters[0] ?? null;
|
|
|
|
return [$message, $count];
|
|
|
|
}
|
2020-07-18 20:26:57 +02:00
|
|
|
}
|
|
|
|
CODE_SAMPLE,
|
2020-07-22 15:08:40 +02:00
|
|
|
// e.g. link to RFC or headline in upgrade guide, 1 or more in the list
|
2020-07-29 02:27:21 +02:00
|
|
|
RecipeOption::SOURCE => [
|
|
|
|
'https://github.com/nette/utils/pull/178'
|
2020-07-18 20:26:57 +02:00
|
|
|
],
|
2020-07-29 02:27:21 +02:00
|
|
|
// e.g. symfony30, target set to add this Rule to; keep null if part of core
|
|
|
|
RecipeOption::SET => null,
|
|
|
|
|
|
|
|
// OPTIONAL: only when configured
|
|
|
|
RecipeOption::RULE_CONFIGURATION => null,
|
|
|
|
|
|
|
|
// OPTIONAL: extra file
|
|
|
|
RecipeOption::EXTRA_FILE_NAME => null,
|
|
|
|
RecipeOption::EXTRA_FILE_CONTENT => null,
|
2020-07-18 20:26:57 +02:00
|
|
|
]);
|
|
|
|
};
|