Completed
Pull Request — master (#1)
by Marcelo
43:09 queued 18:08
created

CsFixerFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
namespace Bro\Code;
4
5
use Symfony\CS\Console\Application;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class CsFixerFactory
9
{
10
    /**
11
     * @param array $config
12
     *
13
     * @return Application
14
     */
15
    public function create(array $config)
16
    {
17
        $broLibPath = dirname(dirname($config['binFilePath']));
18
        $preset = $config['preset'];
19
20
        $vendoredPath = $broLibPath . '/../../bro/code';
21
22
        $application = new Application();
23
24
        if (file_exists($vendoredPath)) {
25
            $broLibPath = $vendoredPath;
26
        }
27
28
        $broConfigPath = $broLibPath . '/presets/' . basename($preset) . '.php';
29
        $this->extendApplication($application, $broConfigPath);
30
31
        return $application;
32
    }
33
34
    private function extendApplication(Application $application, $defaultConfigFile)
35
    {
36
        if (file_exists($defaultConfigFile)) {
37
            $fixCommand = $application->find('fix');
38
            /* @var InputOption $configFile */
39
            $definition = $fixCommand->getDefinition();
40
            $options = $definition->getOptions();
41
            $options['config-file']->setDefault(realpath($defaultConfigFile));
42
        }
43
    }
44
}
45