Test Failed
Push — master ( 83b81c...cf0477 )
by BruceScrutinizer
02:27
created

Config::cloneWithWithOverride()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 2
dl 0
loc 18
rs 9.8333
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Config::getVersion() 0 4 1
A Config::enabledCache() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace NamespaceProtector\Config;
4
5
use NamespaceProtector\Common\PathInterface;
6
use Webmozart\Assert\Assert;
7
8
final class Config
9
{
10
    public const MODE_MAKE_VENDOR_PRIVATE = 'MODE_MAKE_VENDOR_PRIVATE';
11
    public const MODE_PUBLIC = 'PUBLIC';
12
    public const MODE_AUTODISCOVER = 'MODE_AUTODISCOVER';
13
14
    public const PLOTTER_TERMINAL = 'plotter-terminal';
15
    public const PLOTTER_PNG = 'plotter-png';
16
17
    /** @var PathInterface */
18
    private $pathStart;
19
20
    /** @var PathInterface  */
21
    private $pathComposerJson;
22
23
    private array $privateEntries;
24
25
    private array $publicEntries;
26
27
    /** @var string */
28
    private $mode;
29
30
    /** @var string */
31
    private $version;
32
33
    /** @var bool */
34
    private $enabledCache;
35
36
    /** @var string */
37
    private $plotter;
38
39
    public function __construct(
40
        string $version,
41
        PathInterface $pathStart,
42
        PathInterface $pathComposerJson,
43
        array $privateEntries,
44
        array $publicEntries,
45
        string $mode = self::MODE_PUBLIC,
46
        bool $enabledCache = false,
47
        string $plotter = self::PLOTTER_TERMINAL
48
    ) {
49
        $this->version = $version;
50
        $this->pathStart = $pathStart;
51
        $this->pathComposerJson = $pathComposerJson;
52
        $this->privateEntries = $privateEntries;
53
        $this->publicEntries = $publicEntries;
54
        $this->mode = $mode;
55
        $this->enabledCache = $enabledCache;
56
        $this->plotter = $plotter;
57
    }
58
59
    public function getStartPath(): PathInterface
60
    {
61
        return $this->pathStart;
62
    }
63
64
    public function getPrivateEntries(): array
65
    {
66
        return $this->privateEntries;
67
    }
68
69
    public function getPublicEntries(): array
70
    {
71
        return $this->publicEntries;
72
    }
73
74
    public function getMode(): string
75
    {
76
        return $this->mode;
77
    }
78
79
    public function getPlotter(): string
80
    {
81
        return $this->plotter;
82
    }
83
84
    public function getPathComposerJson(): PathInterface
85
    {
86
        return $this->pathComposerJson;
87
    }
88
89
    public function validateLoadedConfig(): void
90
    {
91
        Assert::inArray($this->getMode(), [self::MODE_PUBLIC, self::MODE_MAKE_VENDOR_PRIVATE], 'Mode not valid');
92
        Assert::eq('0.1.0', $this->getVersion(), 'Version not valid');
93
        Assert::directory($this->getStartPath()->get(), 'Start directory not valid');
94
        Assert::directory($this->getPathComposerJson()->get(), 'Composer json directory not valid');
95
        Assert::boolean($this->enabledCache(), 'Cache flag must be boolean');
96
        Assert::inArray($this->getPlotter(), [self::PLOTTER_TERMINAL, self::PLOTTER_PNG], 'Plotter not valid');
97
    }
98
99
    public function getVersion(): string
100
    {
101
        //todo: use https://github.com/nikolaposa/version
102
        return $this->version;
103
    }
104
105
    public function enabledCache(): bool
106
    {
107
        return $this->enabledCache;
108
    }
109
}
110