rector/create-rector.php.dist
2020-07-29 02:27:21 +02:00

63 lines
1.8 KiB
Plaintext

<?php
declare(strict_types=1);
use PhpParser\Node\Expr\MethodCall;
use Rector\Core\Configuration\Option;
use Rector\RectorGenerator\ValueObject\RecipeOption;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
// run "bin/rector create" to create a new Rector + tests from this config
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::RECTOR_RECIPE, [
RecipeOption::PACKAGE => 'Nette',
RecipeOption::NAME => 'TranslateClassMethodToVariadicsRector',
RecipeOption::NODE_TYPES => [
MethodCall::class,
],
RecipeOption::DESCRIPTION => 'Change translate() method call 2nd arg to variadic',
RecipeOption::CODE_BEFORE => <<<'CODE_SAMPLE'
<?php
use Nette\Localization\ITranslator;
final class SomeClass implements ITranslator
{
public function translate($message, $count = null)
{
return [$message, $count];
}
}
CODE_SAMPLE,
RecipeOption::CODE_AFTER => <<<'CODE_SAMPLE'
<?php
use Nette\Localization\ITranslator;
final class SomeClass implements ITranslator
{
public function translate($message, ... $parameters)
{
$count = $parameters[0] ?? null;
return [$message, $count];
}
}
CODE_SAMPLE,
// e.g. link to RFC or headline in upgrade guide, 1 or more in the list
RecipeOption::SOURCE => [
'https://github.com/nette/utils/pull/178'
],
// 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,
]);
};