-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectorCommand.php
More file actions
56 lines (44 loc) · 1.44 KB
/
RectorCommand.php
File metadata and controls
56 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace KaririCode\Devkit\Command;
use KaririCode\Devkit\Core\Devkit;
use Override;
/**
* Runs Rector. Default: dry-run preview. Pass `--fix` to apply changes.
*
* @since 1.0.0
*/
final class RectorCommand extends AbstractCommand
{
#[Override]
public function name(): string
{
return 'rector';
}
#[Override]
public function description(): string
{
return 'Run Rector (--fix to apply changes)';
}
#[Override]
public function execute(Devkit $devkit, array $arguments): int
{
$apply = $this->hasFlag($arguments, '--fix', '--apply');
$mode = $apply ? 'applying' : 'previewing';
$this->banner("KaririCode Devkit — Rector ({$mode})");
$passthrough = $this->passthrough($arguments, ['--fix', '--apply']);
// RectorRunner defaults to --dry-run (preview only).
// RectorApplyRunner runs without --dry-run (applies changes).
$result = $apply
? $devkit->run('rector-apply', $passthrough)
: $devkit->run('rector', $passthrough);
$this->line($result->output());
$this->line();
if ($result->success) {
$this->info(\sprintf('Rector %s (%.2fs)', $apply ? 'applied' : 'clean', $result->elapsedSeconds));
} else {
$this->error(\sprintf('Rector found issues (%.2fs)', $result->elapsedSeconds));
}
return $result->exitCode;
}
}