ConfigFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace SugaredRim\PhpCsFixer;
4
5
use Schnittstabil\Get;
6
use Schnittstabil\ComposerExtra\ComposerExtra;
7
use Schnittstabil\FinderByConfig\FinderByConfig;
8
9
class ConfigFactory
10
{
11
    protected $defaults;
12
13
    public function __construct()
14
    {
15
        $this->defaults = new \stdClass();
16
        $this->defaults->presets = [
17
            'SugaredRim\\PhpCsFixer\\DefaultPreset::get',
18
        ];
19
    }
20
21
    protected function getComposerConfig($namespace)
22
    {
23
        return (new ComposerExtra(
24
            $namespace,
25
            $this->defaults,
26
            'presets'
27
        ))->get();
28
    }
29
30
    public function __invoke($namespace)
31
    {
32
        $composerConfig = $this->getComposerConfig($namespace);
33
        $config = new Config();
34
35
        $config->diff = Get\value('diff', $composerConfig, false);
36
        $config->{'dry-run'} = Get\value('dry-run', $composerConfig, false);
37
        $config->setUsingCache(Get\value('cache', $composerConfig, false));
38
39
        $path = Get\value('path', $composerConfig);
40
        if (!empty($path)) {
41
            $finderByConfig = new FinderByConfig();
42
            $config->setFinder($finderByConfig($path));
43
        }
44
45
        return $config;
46
    }
47
}
48