Skip to content

Commit 33f6731

Browse files
committed
Enable symfony composer-based set in rector.php
- add symfony: true to withComposerBased() - fix fatal error in "composer-based" command on lazily-initialized typed properties (PHPStan UnionType::$normalized) - skip ConsoleExecuteReturnIntRector, it adds a redundant (int) cast that RecastingRemovalRector removes again
1 parent 4e11a40 commit 33f6731

7 files changed

Lines changed: 22 additions & 30 deletions

File tree

‎rector.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
99
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
1010
use Rector\Php84\Rector\Class_\DeprecatedAnnotationToDeprecatedAttributeRector;
11+
use Rector\Symfony\Symfony44\Rector\ClassMethod\ConsoleExecuteReturnIntRector;
1112

1213
return RectorConfig::configure()
1314
->withPreparedSets(
@@ -24,7 +25,7 @@
2425
phpunitCodeQuality: true
2526
)
2627
->withAttributesSets()
27-
->withComposerBased(phpunit: true)
28+
->withComposerBased(phpunit: true, symfony: true)
2829
->withPhpSets()
2930
->withPaths([
3031
__DIR__ . '/bin',
@@ -41,6 +42,9 @@
4142
->withImportNames()
4243
->withSkip([
4344
StringClassNameToClassConstantRector::class,
45+
46+
// adds (int) cast to methods that already return int, ping-pongs with RecastingRemovalRector
47+
ConsoleExecuteReturnIntRector::class,
4448
// tests
4549
'*/Fixture*',
4650
'*/Source*',

‎src/Console/Command/ComposerBasedCommand.php‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
1414
use Rector\VersionBonding\ValueObject\ComposerBoundRuleConfiguration;
1515
use ReflectionObject;
16+
use Symfony\Component\Console\Attribute\AsCommand;
1617
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Helper\TableCell;
1819
use Symfony\Component\Console\Helper\TableSeparator;
@@ -23,6 +24,7 @@
2324
/**
2425
* @see \Rector\Tests\Console\Command\ComposerBasedCommandTest
2526
*/
27+
#[AsCommand(name: 'composer-based', description: 'Show loaded rules that are triggered by an installed composer package version')]
2628
final class ComposerBasedCommand extends Command
2729
{
2830
/**
@@ -36,12 +38,6 @@ public function __construct(
3638
parent::__construct();
3739
}
3840

39-
protected function configure(): void
40-
{
41-
$this->setName('composer-based');
42-
$this->setDescription('Show loaded rules that are triggered by an installed composer package version');
43-
}
44-
4541
protected function execute(InputInterface $input, OutputInterface $output): int
4642
{
4743
$tableRows = $this->createTableRows();
@@ -206,6 +202,11 @@ private function printConfigurationValue(mixed $value): string
206202

207203
$reflectionObject = new ReflectionObject($value);
208204
foreach ($reflectionObject->getProperties() as $reflectionProperty) {
205+
// lazy-initialized property, e.g. PHPStan UnionType::$normalized
206+
if (! $reflectionProperty->isInitialized($value)) {
207+
continue;
208+
}
209+
209210
$printedPropertyValues[] = $this->printConfigurationValue($reflectionProperty->getValue($value));
210211
}
211212

‎src/Console/Command/CustomRuleCommand.php‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
use Rector\Enum\ClassName;
1111
use Rector\Exception\ShouldNotHappenException;
1212
use Rector\FileSystem\JsonFileSystem;
13+
use Symfony\Component\Console\Attribute\AsCommand;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\Console\Style\SymfonyStyle;
1718
use Symfony\Component\Finder\Finder;
1819
use Symfony\Component\Finder\SplFileInfo;
1920

21+
#[AsCommand(name: 'custom-rule', description: 'Create base of local custom rule with tests')]
2022
final class CustomRuleCommand extends Command
2123
{
2224
public function __construct(
@@ -26,12 +28,6 @@ public function __construct(
2628
parent::__construct();
2729
}
2830

29-
protected function configure(): void
30-
{
31-
$this->setName('custom-rule');
32-
$this->setDescription('Create base of local custom rule with tests');
33-
}
34-
3531
protected function execute(InputInterface $input, OutputInterface $output): int
3632
{
3733
// ask for rule name

‎src/Console/Command/ListRulesCommand.php‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
use Rector\Contract\Rector\RectorInterface;
1111
use Rector\PostRector\Contract\Rector\PostRectorInterface;
1212
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
13+
use Symfony\Component\Console\Attribute\AsCommand;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Input\InputOption;
1617
use Symfony\Component\Console\Output\OutputInterface;
1718
use Symfony\Component\Console\Style\SymfonyStyle;
1819

20+
#[AsCommand(name: 'list-rules', description: 'Show loaded Rectors', aliases: ['show-rules'])]
1921
final class ListRulesCommand extends Command
2022
{
2123
/**
@@ -31,11 +33,6 @@ public function __construct(
3133

3234
protected function configure(): void
3335
{
34-
$this->setName('list-rules');
35-
$this->setDescription('Show loaded Rectors');
36-
37-
$this->setAliases(['show-rules']);
38-
3936
$this->addOption(
4037
Option::OUTPUT_FORMAT,
4138
null,

‎src/Console/Command/ProcessCommand.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
use Rector\ValueObject\Configuration\LevelOverflow;
2727
use Rector\ValueObject\ProcessResult;
2828
use Symfony\Component\Console\Application;
29+
use Symfony\Component\Console\Attribute\AsCommand;
2930
use Symfony\Component\Console\Command\Command;
3031
use Symfony\Component\Console\Input\InputInterface;
3132
use Symfony\Component\Console\Output\OutputInterface;
3233
use Symfony\Component\Console\Style\SymfonyStyle;
3334

35+
#[AsCommand(name: 'process', description: 'Upgrades or refactors source code with provided Rector rules', aliases: ['p'])]
3436
final class ProcessCommand extends Command
3537
{
3638
public function __construct(
@@ -53,9 +55,6 @@ public function __construct(
5355

5456
protected function configure(): void
5557
{
56-
$this->setName('process');
57-
$this->setAliases(['p']);
58-
$this->setDescription('Upgrades or refactors source code with provided Rector rules');
5958
$this->setHelp(
6059
<<<'EOF'
6160
The <info>%command.name%</info> command will run Rector main feature:

‎src/Console/Command/SetupCICommand.php‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use Nette\Utils\FileSystem;
88
use OndraM\CiDetector\CiDetector;
99
use Rector\Git\RepositoryHelper;
10+
use Symfony\Component\Console\Attribute\AsCommand;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314
use Symfony\Component\Console\Style\SymfonyStyle;
1415
use function sprintf;
1516

17+
#[AsCommand(name: 'setup-ci', description: 'Add CI workflow to let Rector work for you')]
1618
final class SetupCICommand extends Command
1719
{
1820
public function __construct(
@@ -21,12 +23,6 @@ public function __construct(
2123
parent::__construct();
2224
}
2325

24-
protected function configure(): void
25-
{
26-
$this->setName('setup-ci');
27-
$this->setDescription('Add CI workflow to let Rector work for you');
28-
}
29-
3026
protected function execute(InputInterface $input, OutputInterface $output): int
3127
{
3228
// detect current CI

‎src/Console/Command/WorkerCommand.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Rector\Util\MemoryLimiter;
2121
use Rector\ValueObject\Configuration;
2222
use Rector\ValueObject\Error\SystemError;
23+
use Symfony\Component\Console\Attribute\AsCommand;
2324
use Symfony\Component\Console\Command\Command;
2425
use Symfony\Component\Console\Input\InputInterface;
2526
use Symfony\Component\Console\Output\OutputInterface;
@@ -36,6 +37,7 @@
3637
* ↓↓↓
3738
* https://github.com/phpstan/phpstan-src/commit/b84acd2e3eadf66189a64fdbc6dd18ff76323f67#diff-7f625777f1ce5384046df08abffd6c911cfbb1cfc8fcb2bdeaf78f337689e3e2
3839
*/
40+
#[AsCommand(name: 'worker', description: '[INTERNAL] Support for parallel process')]
3941
final class WorkerCommand extends Command
4042
{
4143
private const string RESULT = 'result';
@@ -53,9 +55,6 @@ public function __construct(
5355

5456
protected function configure(): void
5557
{
56-
$this->setName('worker');
57-
$this->setDescription('[INTERNAL] Support for parallel process');
58-
5958
ProcessConfigureDecorator::decorate($this);
6059

6160
parent::configure();

0 commit comments

Comments
 (0)