4
4
5
5
use App \Factories \ConfigurationResolverFactory ;
6
6
use LaravelZero \Framework \Exceptions \ConsoleException ;
7
+ use PhpCsFixer \Console \ConfigurationResolver ;
7
8
use PhpCsFixer \Runner \Runner ;
9
+ use Symfony \Component \Console \Input \InputInterface ;
10
+ use Symfony \Component \Console \Input \InputOption ;
8
11
9
12
class FixCode
10
13
{
@@ -45,8 +48,10 @@ public function execute()
45
48
$ this ->progress ->subscribe ();
46
49
}
47
50
51
+ $ method = $ this ->input ->getOption ('parallel ' ) ? 'fixParallel ' : 'fixSequential ' ;
52
+
48
53
/** @var array<string, array{appliedFixers: array<int, string>, diff: string}> $changes */
49
- $ changes = (new Runner (
54
+ $ changes = (fn () => $ this ->{ $ method }())-> call ( new Runner (
50
55
$ resolver ->getFinder (),
51
56
$ resolver ->getFixers (),
52
57
$ resolver ->getDiffer (),
@@ -56,9 +61,34 @@ public function execute()
56
61
$ resolver ->isDryRun (),
57
62
$ resolver ->getCacheManager (),
58
63
$ resolver ->getDirectory (),
59
- $ resolver ->shouldStopOnViolation ()
60
- ))->fix ();
64
+ $ resolver ->shouldStopOnViolation (),
65
+ $ resolver ->getParallelConfig (),
66
+ $ this ->getInput ($ resolver ),
67
+ ));
61
68
62
69
return tap ([$ totalFiles , $ changes ], fn () => $ this ->progress ->unsubscribe ());
63
70
}
71
+
72
+ /**
73
+ * Gets the input for the PHP CS Fixer Runner.
74
+ */
75
+ private function getInput (ConfigurationResolver $ resolver ): InputInterface
76
+ {
77
+ // @phpstan-ignore-next-line
78
+ $ definition = (fn () => $ this ->definition )->call ($ this ->input );
79
+
80
+ $ definition ->addOptions ([
81
+ new InputOption ('stop-on-violation ' , null , InputOption::VALUE_REQUIRED , '' ),
82
+ new InputOption ('allow-risky ' , null , InputOption::VALUE_REQUIRED , '' ),
83
+ new InputOption ('rules ' , null , InputOption::VALUE_REQUIRED , '' ),
84
+ new InputOption ('using-cache ' , null , InputOption::VALUE_REQUIRED , '' ),
85
+ ]);
86
+
87
+ $ this ->input ->setOption ('stop-on-violation ' , $ resolver ->shouldStopOnViolation ());
88
+ $ this ->input ->setOption ('allow-risky ' , $ resolver ->getRiskyAllowed () ? 'yes ' : 'no ' );
89
+ $ this ->input ->setOption ('rules ' , json_encode ($ resolver ->getRules ()));
90
+ $ this ->input ->setOption ('using-cache ' , $ resolver ->getUsingCache () ? 'yes ' : 'no ' );
91
+
92
+ return $ this ->input ;
93
+ }
64
94
}
0 commit comments