ConfigFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getComposerConfig() 0 8 1
A __invoke() 0 17 2
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