Skip to content

Commit 7d48573

Browse files
committed
feat(rector): add RectorApplyRunner and fix --no-dry-run obsolete flag
Rector removed the --no-dry-run option. Fix: - Add RectorApplyRunner: runs rector process without --dry-run (apply mode) - Register RectorApplyRunner in bin/kcode - Fix FormatCommand: use rector-apply runner (applies changes, not dry-run) - Fix RectorCommand: use rector-apply when --fix/--apply flag passed kcode format now correctly applies cs-fixer + rector changes without error.
1 parent 31fe5f5 commit 7d48573

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

bin/kcode

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ declare(strict_types=1);
6868
$devkit->addRunner(new \KaririCode\Devkit\Runner\PhpStanRunner($executor, $context));
6969
$devkit->addRunner(new \KaririCode\Devkit\Runner\CsFixerRunner($executor, $context));
7070
$devkit->addRunner(new \KaririCode\Devkit\Runner\RectorRunner($executor, $context));
71+
$devkit->addRunner(new \KaririCode\Devkit\Runner\RectorApplyRunner($executor, $context));
7172
$devkit->addRunner(new \KaririCode\Devkit\Runner\PsalmRunner($executor, $context));
7273
$devkit->addRunner(new \KaririCode\Devkit\Runner\ComposerAuditRunner($executor, $context));
7374
}

build/kcode.phar

1.19 KB
Binary file not shown.

src/Command/FormatCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public function execute(Devkit $devkit, array $arguments): int
5050
}
5151

5252
// Step 2: Rector apply (--no-dry-run overrides runner default)
53-
if ($devkit->isToolAvailable('rector')) {
53+
if ($devkit->isToolAvailable('rector-apply')) {
5454
$this->line("\033[1m▸ Running rector process…\033[0m");
55-
$result = $devkit->run('rector', ['--no-dry-run', ...$arguments]);
55+
$result = $devkit->run('rector-apply', $arguments);
5656
$this->line($result->output());
5757

5858
if ($result->success) {

src/Command/RectorCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public function execute(Devkit $devkit, array $arguments): int
3636

3737
$passthrough = $this->passthrough($arguments, ['--fix', '--apply']);
3838

39-
// RectorRunner defaults to --dry-run for safety.
40-
// When applying, --no-dry-run overrides it (Rector: last flag wins).
39+
// RectorRunner defaults to --dry-run (preview only).
40+
// RectorApplyRunner runs without --dry-run (applies changes).
4141
$result = $apply
42-
? $devkit->run('rector', ['--no-dry-run', ...$passthrough])
42+
? $devkit->run('rector-apply', $passthrough)
4343
: $devkit->run('rector', $passthrough);
4444

4545
$this->line($result->output());

src/Runner/RectorApplyRunner.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Devkit\Runner;
6+
7+
use Override;
8+
9+
/**
10+
* Runs Rector without --dry-run, applying all changes.
11+
*
12+
* Used by FormatCommand and RectorCommand (with --fix) to actually write
13+
* the changes to disk, as opposed to RectorRunner which only previews.
14+
*
15+
* @since 1.0.0
16+
*/
17+
final class RectorApplyRunner extends AbstractToolRunner
18+
{
19+
#[Override]
20+
public function toolName(): string
21+
{
22+
return 'rector-apply';
23+
}
24+
25+
#[Override]
26+
protected function vendorBin(): string
27+
{
28+
return 'vendor/bin/rector';
29+
}
30+
31+
#[Override]
32+
protected function defaultArguments(): array
33+
{
34+
return [
35+
'process',
36+
'--config',
37+
$this->context->configPath('rector.php'),
38+
'--ansi',
39+
];
40+
}
41+
}

0 commit comments

Comments
 (0)