-
-
Notifications
You must be signed in to change notification settings - Fork 727
Closed
rectorphp/rector-symfony
#790Description
Bug Report
Subject | Details |
---|---|
Rector version | 2.0.17 |
When applying InvokableCommandInputAttributeRector
, using an option name that includes a hyphen results in the generation of an invalid variable name.
Minimal PHP Code Causing Issue
Original code:
<?php
declare(strict_types=1);
namespace App\Entrypoint\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'sync:test_rector', description: 'Hello PhpStorm')]
class TestRectorCommand extends Command
{
protected function configure(): void
{
$this->addOption('option-with-hyphen');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
return Command::SUCCESS;
}
}
After applying the rector rule, the generated code incorrectly includes a variable name with hyphens, which is not valid in PHP:
<?php
declare(strict_types=1);
namespace App\Entrypoint\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'sync:test_rector', description: 'Hello PhpStorm')]
class TestRectorCommand
{
public function __invoke(#[\Symfony\Component\Console\Attribute\Command\Option]
$option-with-hyphen, OutputInterface $output): int
{
return Command::SUCCESS;
}
}
Expected Behaviour
<?php
declare(strict_types=1);
namespace App\Entrypoint\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'sync:test_rector', description: 'Hello PhpStorm')]
class TestRectorCommand
{
public function __invoke(#[\Symfony\Component\Console\Attribute\Command\Option]
$option_with_hyphen, OutputInterface $output): int
{
return Command::SUCCESS;
}
}