Skip to content

Commit 3786ceb

Browse files
authored
[Symfony 7.3] Make __invoke() public in InvokableCommandInputAttributeRector (rectorphp#779)
1 parent 13a3990 commit 3786ceb

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/name_from_constant.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class NameFromConstant
5252
{
5353
private const string ARGUMENT_NAME = 'name';
5454

55-
protected function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: self::ARGUMENT_NAME, description: 'The name of the person to greet.')]
55+
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: self::ARGUMENT_NAME, description: 'The name of the person to greet.')]
5656
?string $name, OutputInterface $output): int
5757
{
5858
$name = $name;
@@ -61,4 +61,4 @@ class NameFromConstant
6161
}
6262
}
6363

64-
?>
64+
?>

rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/some_command_with_set_help.php.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use Symfony\Component\Console\Input\InputOption;
1212
#[AsCommand(name: 'some_name')]
1313
final class SomeCommandWithSetHelp extends Command
1414
{
15-
public function configure()
15+
protected function configure()
1616
{
1717
$this->setHelp('argument');
1818
$this->addArgument('argument', InputArgument::REQUIRED, 'Argument description');
1919
$this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
2020
}
2121

22-
public function execute(InputInterface $input, OutputInterface $output): int
22+
protected function execute(InputInterface $input, OutputInterface $output): int
2323
{
2424
$someArgument = $input->getArgument('argument');
2525
$someOption = $input->getOption('option');
@@ -46,7 +46,7 @@ use Symfony\Component\Console\Input\InputOption;
4646
#[AsCommand(name: 'some_name')]
4747
final class SomeCommandWithSetHelp
4848
{
49-
public function configure()
49+
protected function configure()
5050
{
5151
$this->setHelp('argument');
5252
}

rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/with_optional_argument.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use Symfony\Component\Console\Input\InputOption;
1212
#[AsCommand(name: 'some_name')]
1313
final class WithOptionalArgument extends Command
1414
{
15-
public function configure()
15+
protected function configure()
1616
{
1717
$this->addArgument('argument', InputArgument::OPTIONAL, 'Argument description');
1818
$this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
1919
}
2020

21-
public function execute(InputInterface $input, OutputInterface $output): int
21+
protected function execute(InputInterface $input, OutputInterface $output): int
2222
{
2323
$someArgument = $input->getArgument('argument');
2424
$someOption = $input->getOption('option');

rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/with_override.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ use Symfony\Component\Console\Input\InputOption;
1313
final class WithOverride extends Command
1414
{
1515
#[\Override]
16-
public function configure()
16+
protected function configure()
1717
{
1818
$this->addArgument('argument', InputArgument::REQUIRED, 'Argument description');
1919
$this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
2020
}
2121

2222
#[\Override]
23-
public function execute(InputInterface $input, OutputInterface $output): int
23+
protected function execute(InputInterface $input, OutputInterface $output): int
2424
{
2525
$someArgument = $input->getArgument('argument');
2626
$someOption = $input->getOption('option');

rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
2020
use Rector\Exception\ShouldNotHappenException;
2121
use Rector\PhpParser\Node\Value\ValueResolver;
22+
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
2223
use Rector\Rector\AbstractRector;
2324
use Rector\Symfony\Enum\CommandMethodName;
2425
use Rector\Symfony\Enum\SymfonyAttribute;
@@ -42,7 +43,8 @@ public function __construct(
4243
private readonly AttributeFinder $attributeFinder,
4344
private readonly CommandArgumentsAndOptionsResolver $commandArgumentsAndOptionsResolver,
4445
private readonly CommandInvokeParamsFactory $commandInvokeParamsFactory,
45-
private readonly ValueResolver $valueResolver
46+
private readonly ValueResolver $valueResolver,
47+
private readonly VisibilityManipulator $visibilityManipulator,
4648
) {
4749
}
4850

@@ -147,6 +149,7 @@ public function refactor(Node $node): ?Class_
147149
}
148150

149151
$executeClassMethod->name = new Identifier('__invoke');
152+
$this->visibilityManipulator->makePublic($executeClassMethod);
150153

151154
// 3. create arguments and options parameters
152155
// @todo

0 commit comments

Comments
 (0)