CsFixerFactory::extendApplication()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

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