Skip to content

Commit 42c924a

Browse files
authored
[dx] Prepend command name automatically if only paths are passed (#6759)
* [dx] prepare command name if nothing passed * [readme] update to run without explicit command * bump deps, use phpecs package * [ci] add bare --help and --version run
1 parent a2d3a9a commit 42c924a

File tree

7 files changed

+36
-11
lines changed

7 files changed

+36
-11
lines changed

.github/workflows/code_analysis.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jobs:
2929
name: 'PHPStan'
3030
run: vendor/bin/phpstan analyse --ansi
3131

32+
-
33+
name: 'Help and Version'
34+
run:
35+
bin/rector --help
36+
bin/rector --version
37+
3238
-
3339
name: 'Commented Code'
3440
run: vendor/bin/swiss-knife check-commented-code src rules tests rules-tests --line-limit 5 --ansi

build/target-repository/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ return RectorConfig::configure()
6060
Then dry run Rector:
6161

6262
```bash
63-
vendor/bin/rector process src --dry-run
63+
vendor/bin/rector src --dry-run
6464
```
6565

6666
Rector will show you diff of files that it *would* change. To *make* the changes, drop `--dry-run`:
6767

6868
```bash
69-
vendor/bin/rector process src
69+
vendor/bin/rector src
7070
```
7171

7272
## Documentation
@@ -124,7 +124,7 @@ See [the contribution guide](/CONTRIBUTING.md) or go to development repository [
124124
You can use `--debug` option, that will print nested exceptions output:
125125

126126
```bash
127-
vendor/bin/rector process src/Controller --dry-run --debug
127+
vendor/bin/rector src/Controller --dry-run --debug
128128
```
129129

130130
Or with Xdebug:
@@ -133,7 +133,7 @@ Or with Xdebug:
133133
2. Add `--xdebug` option when running Rector
134134

135135
```bash
136-
vendor/bin/rector process src/Controller --dry-run --xdebug
136+
vendor/bin/rector src/Controller --dry-run --xdebug
137137
```
138138

139139
To assist with simple debugging Rector provides 2 helpers to pretty-print AST-nodes:

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
"rector/swiss-knife": "^2.0",
5454
"rector/type-perfect": "^2.0",
5555
"shipmonk/composer-dependency-analyser": "^1.8",
56-
"symplify/easy-coding-standard": "^12.5",
56+
"phpecs/phpecs": "^2.1",
5757
"symplify/phpstan-extensions": "^12.0",
58-
"symplify/phpstan-rules": "^14.0",
59-
"symplify/vendor-patches": "^11.3",
58+
"symplify/phpstan-rules": "^14.5",
59+
"symplify/vendor-patches": "^11.4",
6060
"tomasvotruba/class-leak": "^2.0",
6161
"tracy/tracy": "^2.10"
6262
},

ecs.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer;
65
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer;
76
use Symplify\EasyCodingStandard\Config\ECSConfig;
87

src/Console/Command/ProcessCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
105105
$this->reportLevelOverflow($levelOverflow);
106106
}
107107

108-
// 0. warn about rules registered in both withRules() and sets to avoid bloated rector.php configs
108+
// 1. warn about rules registered in both withRules() and sets to avoid bloated rector.php configs
109109
$setAndRulesDuplicatedRegistrations = $configuration->getBothSetAndRulesDuplicatedRegistrations();
110110
if ($setAndRulesDuplicatedRegistrations !== []) {
111111
$this->symfonyStyle->warning(sprintf(
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115115
));
116116
}
117117

118-
// 1. add files and directories to static locator
118+
// 2. add files and directories to static locator
119119
$this->dynamicSourceLocatorDecorator->addPaths($paths);
120120
if ($this->dynamicSourceLocatorDecorator->isPathsEmpty()) {
121121
// read from rector.php, no paths definition needs withPaths() config

src/Console/ConsoleApplication.php

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rector\Application\VersionResolver;
99
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
1010
use Rector\Configuration\Option;
11+
use Rector\Util\Reflection\PrivatesAccessor;
1112
use Symfony\Component\Console\Application;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputDefinition;
@@ -61,6 +62,18 @@ public function doRun(InputInterface $input, OutputInterface $output): int
6162
$output->write(PHP_EOL);
6263
}
6364

65+
$commandName = $input->getFirstArgument();
66+
67+
// if paths exist
68+
if (is_string($commandName) && file_exists($commandName)) {
69+
// prepend command name if implicit
70+
$privatesAccessor = new PrivatesAccessor();
71+
$tokens = $privatesAccessor->getPrivateProperty($input, 'tokens');
72+
$tokens = array_merge(['process'], $tokens);
73+
74+
$privatesAccessor->setPrivateProperty($input, 'tokens', $tokens);
75+
}
76+
6477
return parent::doRun($input, $output);
6578
}
6679

src/Parallel/Command/WorkerCommandLineFactory.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ public function create(
4141
int $port
4242
): string {
4343
$commandArguments = array_slice($_SERVER['argv'], 1);
44-
$args = [PHP_BINARY, $mainScript, ...$commandArguments];
4544

45+
// add implicit "process" command name if missing
46+
if ($commandArguments !== [] && ($commandArguments[0] !== 'process' && $commandArguments[0] !== 'p') && ! defined(
47+
'PHPUNIT_COMPOSER_INSTALL'
48+
)) {
49+
$commandArguments = array_merge(['process'], $commandArguments);
50+
}
51+
52+
$args = [PHP_BINARY, $mainScript, ...$commandArguments];
4653
$workerCommandArray = [];
4754

4855
$mainCommand = $this->commandFromReflectionFactory->create($mainCommandClass);

0 commit comments

Comments
 (0)