Skip to content

Commit b35457e

Browse files
committed
Refactor to use traits
1 parent 4d23797 commit b35457e

File tree

1 file changed

+12
-113
lines changed

1 file changed

+12
-113
lines changed

src/Services/Fixer.php

Lines changed: 12 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2,138 +2,37 @@
22

33
namespace STS\Fixer\Services;
44

5-
use PhpCsFixer\Config;
65
use PhpCsFixer\ConfigInterface;
7-
use PhpCsFixer\Console\ConfigurationResolver;
8-
use PhpCsFixer\ToolInfo;
96
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;
1111
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;
1713

1814
class Fixer
1915
{
20-
/**
21-
*
22-
* @var array
23-
*/
24-
protected $cliInput;
25-
26-
/**
27-
*
28-
* @var ConfigurationResolver
29-
*/
30-
protected $configResolver;
3116

32-
/**
33-
*
34-
* @var InputInterface
35-
*/
36-
protected $input;
17+
use HasFinder,
18+
HasProgressOutput,
19+
HasRunner,
20+
HasFixEvent;
3721

3822
/**
3923
*
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
5325
*/
54-
protected $progressOutput;
26+
protected $cliInput;
5527

5628

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)
5830
{
59-
$this->input = $input;
6031
$this->output = $output;
6132
$this->cliInput = $cliInput;
6233
$this->setResolver($cliInput, $config, $cwd, $toolInfo);
6334
$this->setEventDispatcher();
6435
$this->setFinder();
6536
$this->setProgressOutput();
6637
}
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-
}
13938
}

0 commit comments

Comments
 (0)