|
2 | 2 |
|
3 | 3 | namespace STS\Fixer\Services;
|
4 | 4 |
|
5 |
| -use PhpCsFixer\Config; |
6 | 5 | use PhpCsFixer\ConfigInterface;
|
7 |
| -use PhpCsFixer\Console\ConfigurationResolver; |
8 |
| -use PhpCsFixer\ToolInfo; |
9 | 6 | use PhpCsFixer\ToolInfoInterface;
|
10 |
| -use Symfony\Component\Console\Input\InputInterface; |
| 7 | + |
| 8 | +use STS\Fixer\Services\Fixer\Concerns\HasRunner; |
| 9 | +use STS\Fixer\Services\Fixer\Concerns\HasFinder; |
| 10 | +use STS\Fixer\Services\Fixer\Concerns\HasFixEvent; |
11 | 11 | use Symfony\Component\Console\Output\OutputInterface;
|
12 |
| -use PhpCsFixer\Console\Output\NullOutput; |
13 |
| -use PhpCsFixer\Console\Output\ProcessOutput; |
14 |
| -use PhpCsFixer\Finder; |
15 |
| -use Symfony\Component\Console\Terminal; |
16 |
| -use Symfony\Component\EventDispatcher\EventDispatcher; |
| 12 | +use STS\Fixer\Services\Fixer\Concerns\HasProgressOutput; |
17 | 13 |
|
18 | 14 | class Fixer
|
19 | 15 | {
|
20 |
| - /** |
21 |
| - * |
22 |
| - * @var array |
23 |
| - */ |
24 |
| - protected $cliInput; |
25 |
| - |
26 |
| - /** |
27 |
| - * |
28 |
| - * @var ConfigurationResolver |
29 |
| - */ |
30 |
| - protected $configResolver; |
31 | 16 |
|
32 |
| - /** |
33 |
| - * |
34 |
| - * @var InputInterface |
35 |
| - */ |
36 |
| - protected $input; |
| 17 | + use HasFinder, |
| 18 | + HasProgressOutput, |
| 19 | + HasRunner, |
| 20 | + HasFixEvent; |
37 | 21 |
|
38 | 22 | /**
|
39 | 23 | *
|
40 |
| - * @var OutputInterface |
41 |
| - */ |
42 |
| - protected $output; |
43 |
| - |
44 |
| - /** |
45 |
| - * |
46 |
| - * @var Finder |
47 |
| - */ |
48 |
| - protected $finder; |
49 |
| - |
50 |
| - /** |
51 |
| - * |
52 |
| - * @var ProcessOutput|NullOutput |
| 24 | + * @var array |
53 | 25 | */
|
54 |
| - protected $progressOutput; |
| 26 | + protected $cliInput; |
55 | 27 |
|
56 | 28 |
|
57 |
| - public function __construct(InputInterface $input, OutputInterface $output, ?array $cliInput = null, ?ConfigInterface $config = null, ?string $cwd = null, ?ToolInfoInterface $toolInfo = null) |
| 29 | + public function __construct(OutputInterface $output, ?array $cliInput = null, ?ConfigInterface $config = null, ?string $cwd = null, ?ToolInfoInterface $toolInfo = null) |
58 | 30 | {
|
59 |
| - $this->input = $input; |
60 | 31 | $this->output = $output;
|
61 | 32 | $this->cliInput = $cliInput;
|
62 | 33 | $this->setResolver($cliInput, $config, $cwd, $toolInfo);
|
63 | 34 | $this->setEventDispatcher();
|
64 | 35 | $this->setFinder();
|
65 | 36 | $this->setProgressOutput();
|
66 | 37 | }
|
67 |
| - |
68 |
| - public function setEventDispatcher(?EventDispatcher $eventDispatcher = null) |
69 |
| - { |
70 |
| - $this->eventDispatcher = $eventDispatcher ?? new EventDispatcher(); |
71 |
| - } |
72 |
| - |
73 |
| - public function setResolver(array $options, ?ConfigInterface $config = null, ?string $cwd = null, ?ToolInfoInterface $toolInfo = null) |
74 |
| - { |
75 |
| - $config = $config ?: new Config(config('fixer.config_name', 'Laravel')); |
76 |
| - $cwd = $cwd ?: getcwd(); |
77 |
| - $toolInfo = $toolInfo ?: new ToolInfo(); |
78 |
| - $this->configResolver = new ConfigurationResolver($config, $options, $cwd, $toolInfo); |
79 |
| - } |
80 |
| - |
81 |
| - public function setFinder() |
82 |
| - { |
83 |
| - $this->finder = Finder::create() |
84 |
| - ->in(config('fixer.find_directories')) |
85 |
| - ->name(config('fixer.file_name_pattern_whitelist')) |
86 |
| - ->notName(config('fixer.file_name_pattern_blacklist')) |
87 |
| - ->ignoreDotFiles(config('fixer.ignore_dot_files')) |
88 |
| - ->ignoreVCS(config('fixer.ignore_vcs')); |
89 |
| - } |
90 |
| - |
91 |
| - public function getLoadedConfigMessage() |
92 |
| - { |
93 |
| - return sprintf( |
94 |
| - 'Loaded config <comment>%s</comment> from %s.', |
95 |
| - $this->configResolver->getConfig()->getName(), |
96 |
| - $this->configResolver->getConfigFile() ?? 'Laravel Fixer Configuration.' |
97 |
| - ); |
98 |
| - } |
99 |
| - |
100 |
| - public function getPhpRuntimeMessage() |
101 |
| - { |
102 |
| - $configFile = $this->configResolver->getConfig()->getPhpExecutable(); |
103 |
| - return sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION); |
104 |
| - } |
105 |
| - |
106 |
| - public function isUsingCache() |
107 |
| - { |
108 |
| - return $this->configResolver->getUsingCache(); |
109 |
| - } |
110 |
| - |
111 |
| - public function cacheFileExists() |
112 |
| - { |
113 |
| - return is_file($this->configResolver->getCacheFile()); |
114 |
| - } |
115 |
| - |
116 |
| - public function getCacheFileMessage() |
117 |
| - { |
118 |
| - return sprintf('Using cache file "%s".', $this->configResolver->getCacheFile()); |
119 |
| - } |
120 |
| - |
121 |
| - /** |
122 |
| - * @param $resolver |
123 |
| - * @param $stdErr |
124 |
| - * |
125 |
| - */ |
126 |
| - protected function setProgressOutput() |
127 |
| - { |
128 |
| - $this->progressOutput = new NullOutput(); |
129 |
| - |
130 |
| - if ('none' !== $this->configResolver->getProgress()) { |
131 |
| - $this->progressOutput = new ProcessOutput( |
132 |
| - $this->output, |
133 |
| - $this->eventDispatcher, |
134 |
| - (new Terminal())->getWidth(), |
135 |
| - $this->finder->count() |
136 |
| - ); |
137 |
| - } |
138 |
| - } |
139 | 38 | }
|
0 commit comments