Skip to content

Commit 02f371f

Browse files
authored
create ClassMethod directly in InvokableCommandInputAttributeRector, to keep newline per attribute (#903)
1 parent 2e30d30 commit 02f371f

12 files changed

Lines changed: 93 additions & 82 deletions

rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'*/Source/*',
2424
'*/Source*/*',
2525
'*/tests/*/Fixture*/Expected/*',
26-
StringClassNameToClassConstantRector::class => [__DIR__ . '/config'],
26+
StringClassNameToClassConstantRector::class => [__DIR__ . '/config', __DIR__ . '/src/Enum'],
2727
UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config'],
2828

2929
RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class => [

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ use Symfony\Component\Console\Output\OutputInterface;
4242
)]
4343
class OptionWithOptionalValue
4444
{
45-
public function __invoke(#[\Symfony\Component\Console\Attribute\Option(name: 'some-array', mode: InputOption::VALUE_IS_ARRAY)]
46-
array $someArray = ['third value'], #[\Symfony\Component\Console\Attribute\Option(name: 'no-default-array', mode: InputOption::VALUE_IS_ARRAY)]
47-
array $noDefaultArray): int
45+
public function __invoke(
46+
#[\Symfony\Component\Console\Attribute\Option(name: 'some-array', mode: InputOption::VALUE_IS_ARRAY)]
47+
array $someArray = ['third value'],
48+
#[\Symfony\Component\Console\Attribute\Option(name: 'no-default-array', mode: InputOption::VALUE_IS_ARRAY)]
49+
array $noDefaultArray
50+
): int
4851
{
4952
}
5053
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use Symfony\Component\Console\Output\OutputInterface;
5151
class NameFromConstant
5252
{
5353
private const string ARGUMENT_NAME = 'name';
54-
5554
public function __invoke(
5655
#[\Symfony\Component\Console\Attribute\Argument(name: self::ARGUMENT_NAME, description: 'The name of the person to greet.')]
5756
?string $name,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ use Symfony\Component\Console\Output\OutputInterface;
4343
)]
4444
class NameWithHyphen
4545
{
46-
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: 'argument-with-hyphen', description: 'Argument description')]
47-
?string $argumentWithHyphen, #[\Symfony\Component\Console\Attribute\Option(name: 'option-with-hyphen')]
48-
$optionWithHyphen): int
46+
public function __invoke(
47+
#[\Symfony\Component\Console\Attribute\Argument(name: 'argument-with-hyphen', description: 'Argument description')]
48+
?string $argumentWithHyphen,
49+
#[\Symfony\Component\Console\Attribute\Option(name: 'option-with-hyphen')]
50+
$optionWithHyphen
51+
): int
4952
{
5053
$argument = $argument_with_hyphen;
5154
$option = $option_with_hyphen;

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@ final class OptionNameConstant
5353
private const ARGUMENT_NAME = 'some-argument';
5454

5555
private const OPTION_NAME = 'some-option';
56-
57-
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: self::ARGUMENT_NAME)]
58-
?string $someArgument, #[\Symfony\Component\Console\Attribute\Option(name: self::OPTION_NAME)]
59-
$someOption): int
56+
public function __invoke(
57+
#[\Symfony\Component\Console\Attribute\Argument(name: self::ARGUMENT_NAME)]
58+
?string $someArgument,
59+
#[\Symfony\Component\Console\Attribute\Option(name: self::OPTION_NAME)]
60+
$someOption
61+
): int
6062
{
6163
$someArgument = $some_argument;
62-
6364
$someOption = $some_option;
64-
6565
// ...
66-
6766
return 1;
6867
}
6968
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ use Symfony\Component\Console\Input\InputOption;
4545
#[AsCommand(name: 'some_name')]
4646
final class SomeCommand
4747
{
48-
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
49-
string $argument, #[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
50-
bool $option = false): int
48+
public function __invoke(
49+
#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
50+
string $argument,
51+
#[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
52+
bool $option = false
53+
): int
5154
{
5255
$someArgument = $argument;
5356
$someOption = $option;
54-
5557
// ...
56-
5758
return 1;
5859
}
5960
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ use Symfony\Component\Console\Input\InputOption;
4646
#[AsCommand(name: 'some_name')]
4747
final class SomeCommandWithMethodChaining
4848
{
49-
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
50-
string $argument, #[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
51-
bool $option = false): int
49+
public function __invoke(
50+
#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
51+
string $argument,
52+
#[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
53+
bool $option = false
54+
): int
5255
{
5356
$someArgument = $argument;
5457
$someOption = $option;
55-
5658
// ...
57-
5859
return 1;
5960
}
6061
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ final class SomeCommandWithSetHelp
5151
$this->setHelp('argument');
5252
}
5353

54-
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
55-
string $argument, #[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
56-
bool $option = false): int
54+
public function __invoke(
55+
#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
56+
string $argument,
57+
#[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
58+
bool $option = false
59+
): int
5760
{
5861
$someArgument = $argument;
5962
$someOption = $option;
60-
6163
// ...
62-
6364
return 1;
6465
}
6566
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ use Symfony\Component\Console\Input\InputOption;
4545
#[AsCommand(name: 'some_name')]
4646
final class WithOptionalArgument
4747
{
48-
public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
49-
?string $argument, #[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
50-
bool $option = false): int
48+
public function __invoke(
49+
#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', description: 'Argument description')]
50+
?string $argument,
51+
#[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')]
52+
bool $option = false
53+
): int
5154
{
5255
$someArgument = $argument;
5356
$someOption = $option;
54-
5557
// ...
56-
5758
return 1;
5859
}
5960
}

rules/CodeQuality/NodeAnalyzer/ParamConverterClassesResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Rector\PhpParser\Node\Value\ValueResolver;
1111
use Rector\Symfony\Enum\SensioAttribute;
1212

13-
final class ParamConverterClassesResolver
13+
final readonly class ParamConverterClassesResolver
1414
{
1515
public function __construct(
1616
private AttributeFinder $attributeFinder,

0 commit comments

Comments
 (0)