Skip to content

Commit 135f0a9

Browse files
committed
[Symfony 7.3] add 7.3 constant and test for 7.3 and support method chaining and test help to attribute
1 parent 9a4e2c8 commit 135f0a9

File tree

18 files changed

+772
-33
lines changed

18 files changed

+772
-33
lines changed

config/sets/symfony/symfony73.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Rector\Symfony\Symfony73\Rector\Class_\CommandHelpToAttributeRector;
67
use Rector\Symfony\Symfony73\Rector\Class_\InvokableCommandRector;
78

89
// @see https://github.com/symfony/symfony/blame/7.3/UPGRADE-7.3.md
910

1011
return RectorConfig::configure()
11-
->withRules([InvokableCommandRector::class]);
12+
->withRules([CommandHelpToAttributeRector::class, InvokableCommandRector::class]);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony61\Rector\Class_\CommandConfigureToAttributeRector\Fixture;
4+
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputOption;
7+
8+
final class CallAllOptions extends \Symfony\Component\Console\Command\Command
9+
{
10+
public function configure()
11+
{
12+
$this->setName('sunshine')
13+
->setDescription('Some description')
14+
->setHidden(false)
15+
->setHelp('Some help text')
16+
->addArgument('argument name')
17+
->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description')
18+
->setAliases(['first', 'second']);
19+
}
20+
}
21+
22+
?>
23+
-----
24+
<?php
25+
26+
namespace Rector\Symfony\Tests\Symfony61\Rector\Class_\CommandConfigureToAttributeRector\Fixture;
27+
28+
use Symfony\Component\Console\Input\InputArgument;
29+
use Symfony\Component\Console\Input\InputOption;
30+
31+
#[\Symfony\Component\Console\Attribute\AsCommand(name: 'sunshine', description: 'Some description', aliases: ['first', 'second'], hidden: false)]
32+
final class CallAllOptions extends \Symfony\Component\Console\Command\Command
33+
{
34+
public function configure()
35+
{
36+
$this
37+
->setHelp('Some help text')
38+
->addArgument('argument name')
39+
->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
40+
}
41+
}
42+
43+
?>

rules-tests/Symfony61/Rector/Class_/CommandConfigureToAttributeRector/Fixture/other-calls-middle.php.inc

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\CommandHelpToAttributeRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class CommandHelpToAttributeRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\CommandHelpToAttributeRector\Fixture;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
8+
#[AsCommand(name: 'some_name')]
9+
final class AddHelpToAttributeCommand extends Command
10+
{
11+
public function configure()
12+
{
13+
$this->setHelp('Some help text');
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\CommandHelpToAttributeRector\Fixture;
22+
23+
use Symfony\Component\Console\Attribute\AsCommand;
24+
use Symfony\Component\Console\Command\Command;
25+
26+
#[AsCommand(name: 'some_name', help: <<<'TXT'
27+
Some help text
28+
TXT)]
29+
final class AddHelpToAttributeCommand extends Command
30+
{
31+
public function configure()
32+
{
33+
}
34+
}
35+
36+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony61\Rector\Class_\CommandConfigureToAttributeRector\Fixture;
4+
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputOption;
7+
8+
#[\Symfony\Component\Console\Attribute\AsCommand(name: 'sunshine', description: 'Some description', aliases: ['first', 'second'], hidden: true)]
9+
final class OtherCallsMiddle extends \Symfony\Component\Console\Command\Command
10+
{
11+
public function configure()
12+
{
13+
$this
14+
->setHelp('Some help text')
15+
->addArgument('argument name')
16+
->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
17+
}
18+
}
19+
20+
?>
21+
-----
22+
<?php
23+
24+
namespace Rector\Symfony\Tests\Symfony61\Rector\Class_\CommandConfigureToAttributeRector\Fixture;
25+
26+
use Symfony\Component\Console\Input\InputArgument;
27+
use Symfony\Component\Console\Input\InputOption;
28+
29+
#[\Symfony\Component\Console\Attribute\AsCommand(name: 'sunshine', description: 'Some description', aliases: ['first', 'second'], hidden: true, help: <<<'TXT'
30+
Some help text
31+
TXT)]
32+
final class OtherCallsMiddle extends \Symfony\Component\Console\Command\Command
33+
{
34+
public function configure()
35+
{
36+
$this
37+
->addArgument('argument name')
38+
->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
39+
}
40+
}
41+
42+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandRector\Fixture;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Input\InputOption;
11+
12+
#[AsCommand(name: 'some_name' , help: 'some_help')]
13+
final class SkipHasHelpAttributeCommand extends Command
14+
{
15+
public function configure()
16+
{
17+
$this->addArgument('argument', InputArgument::REQUIRED, 'Argument description');
18+
$this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
19+
}
20+
21+
public function execute(InputInterface $input, OutputInterface $output): int
22+
{
23+
$someArgument = $input->getArgument('argument');
24+
$someOption = $input->getOption('option');
25+
26+
// ...
27+
28+
return 1;
29+
}
30+
}
31+
32+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\CommandHelpToAttributeRector\Fixture;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
8+
final class SkipNoAsCommandAttributeAndNoHelpAttributeCommand extends Command
9+
{
10+
public function configure()
11+
{
12+
$this->setName('Some command');
13+
}
14+
}
15+
16+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Symfony\Symfony73\Rector\Class_\CommandHelpToAttributeRector;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->rule(CommandHelpToAttributeRector::class);
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandRector\Fixture;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Input\InputOption;
11+
12+
#[AsCommand(name: 'some_name')]
13+
final class SomeCommandWithMethodChaining extends Command
14+
{
15+
public function configure()
16+
{
17+
$this
18+
->addArgument('argument', InputArgument::REQUIRED, 'Argument description')
19+
->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
20+
}
21+
22+
public function execute(InputInterface $input, OutputInterface $output): int
23+
{
24+
$someArgument = $input->getArgument('argument');
25+
$someOption = $input->getOption('option');
26+
27+
// ...
28+
29+
return 1;
30+
}
31+
}
32+
33+
?>
34+
-----
35+
<?php
36+
37+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandRector\Fixture;
38+
39+
use Symfony\Component\Console\Attribute\AsCommand;
40+
use Symfony\Component\Console\Command\Command;
41+
use Symfony\Component\Console\Input\InputInterface;
42+
use Symfony\Component\Console\Output\OutputInterface;
43+
use Symfony\Component\Console\Input\InputArgument;
44+
use Symfony\Component\Console\Input\InputOption;
45+
46+
#[AsCommand(name: 'some_name')]
47+
final class SomeCommandWithMethodChaining
48+
{
49+
public function __invoke(#[\Symfony\Component\Console\Attribute\Command\Argument]
50+
string $argument, #[\Symfony\Component\Console\Attribute\Command\Option]
51+
$option): int
52+
{
53+
$someArgument = $argument;
54+
$someOption = $option;
55+
56+
// ...
57+
58+
return 1;
59+
}
60+
}
61+
62+
?>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandRector\Fixture;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Input\InputOption;
11+
12+
#[AsCommand(name: 'some_name')]
13+
final class SomeCommandWithSetHelp extends Command
14+
{
15+
public function configure()
16+
{
17+
$this->setHelp('argument');
18+
$this->addArgument('argument', InputArgument::REQUIRED, 'Argument description');
19+
$this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
20+
}
21+
22+
public function execute(InputInterface $input, OutputInterface $output): int
23+
{
24+
$someArgument = $input->getArgument('argument');
25+
$someOption = $input->getOption('option');
26+
27+
// ...
28+
29+
return 1;
30+
}
31+
}
32+
33+
?>
34+
-----
35+
<?php
36+
37+
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandRector\Fixture;
38+
39+
use Symfony\Component\Console\Attribute\AsCommand;
40+
use Symfony\Component\Console\Command\Command;
41+
use Symfony\Component\Console\Input\InputInterface;
42+
use Symfony\Component\Console\Output\OutputInterface;
43+
use Symfony\Component\Console\Input\InputArgument;
44+
use Symfony\Component\Console\Input\InputOption;
45+
46+
#[AsCommand(name: 'some_name')]
47+
final class SomeCommandWithSetHelp
48+
{
49+
public function configure()
50+
{
51+
$this->setHelp('argument');
52+
}
53+
54+
public function __invoke(#[\Symfony\Component\Console\Attribute\Command\Argument]
55+
string $argument, #[\Symfony\Component\Console\Attribute\Command\Option]
56+
$option): int
57+
{
58+
$someArgument = $argument;
59+
$someOption = $option;
60+
61+
// ...
62+
63+
return 1;
64+
}
65+
}
66+
67+
?>

0 commit comments

Comments
 (0)