-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathConfigurationResolverFactory.php
More file actions
68 lines (59 loc) · 2.32 KB
/
ConfigurationResolverFactory.php
File metadata and controls
68 lines (59 loc) · 2.32 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
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace App\Factories;
use App\Project;
use App\Repositories\ConfigurationJsonRepository;
use App\Services\PresetManifest;
use ArrayIterator;
use PhpCsFixer\Config;
use PhpCsFixer\Console\ConfigurationResolver;
use PhpCsFixer\ToolInfo;
class ConfigurationResolverFactory
{
/**
* Creates a new PHP CS Fixer Configuration Resolver instance
* from the given input and output.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return array{\PhpCsFixer\Console\ConfigurationResolver, int}
*/
public static function fromIO($input, $output)
{
$path = Project::paths($input);
$localConfiguration = resolve(ConfigurationJsonRepository::class);
$presetManifest = resolve(PresetManifest::class);
$preset = $localConfiguration->preset();
if (! $presetManifest->has($preset)) {
$availablePresets = implode(', ', $presetManifest->names());
abort(1, "Preset '{$preset}' not found. Available presets: {$availablePresets}");
}
$resolver = new ConfigurationResolver(
new Config('default'),
[
'allow-risky' => 'yes',
'config' => $presetManifest->path($preset),
'diff' => $output->isVerbose(),
'dry-run' => $input->getOption('test') || $input->getOption('bail'),
'path' => $path,
'path-mode' => ConfigurationResolver::PATH_MODE_OVERRIDE,
'cache-file' => $input->getOption('cache-file') ?? $localConfiguration->cacheFile() ?? implode(DIRECTORY_SEPARATOR, [
realpath(sys_get_temp_dir()),
md5(
app()->isProduction()
? implode('|', $path)
: (string) microtime()
),
]),
'stop-on-violation' => $input->getOption('bail'),
'verbosity' => $output->getVerbosity(),
'show-progress' => 'true',
],
Project::path(),
new ToolInfo,
);
$totalFiles = count(new ArrayIterator(iterator_to_array(
$resolver->getFinder(),
)));
return [$resolver, $totalFiles];
}
}