CsFixerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90.48%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 37
ccs 19
cts 21
cp 0.9048
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 18 2
A extendApplication() 0 10 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