Passed
Push — master ( da7684...88d58f )
by BruceScrutinizer
02:01
created

ConfigMaker::createFromFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 18
rs 9.8333
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace NamespaceProtector\Config;
4
5
use NamespaceProtector\Common\PathInterface;
6
use NamespaceProtector\Common\FileSystemPath;
7
8
final class ConfigMaker extends AbstractConfigMaker
9
{
10
    public function createFromFile(PathInterface $path): Config
11
    {
12
        $content = \safe\file_get_contents($path->get());
13
        $arrayConfig = \safe\json_decode($content, true);
14
15
        $self = new Config(
16
            $arrayConfig['version'],
17
            new FileSystemPath($arrayConfig['start-path'] ?? '.'),
18
            new FileSystemPath($arrayConfig['composer-json-path'] ?? '.'),
19
            $arrayConfig['private-entries'] ?? [],
20
            $arrayConfig['public-entries'] ?? [],
21
            $arrayConfig['mode'] ?? Config::MODE_PUBLIC,
22
            $arrayConfig['cache'] ?? false,
23
            $arrayConfig['plotter'] ?? Config::PLOTTER_TERMINAL,
24
        );
25
26
        $self->validateLoadedConfig();
27
        return $self;
28
    }
29
30
    /** @param array<string,string> $parameters */
31
    public function createFromItSelf(Config $config, array $parameters): Config
32
    {
33
        $self = new Config(
34
            $config->getVersion(),
35
            $config->getStartPath(),
36
            $config->getPathComposerJson(),
37
            $config->getPrivateEntries(),
38
            $config->getPublicEntries(),
39
            $config->getMode(),
40
            $config->enabledCache(),
41
            $parameters['plotter'] ?? $config->getPlotter(),
42
        );
43
44
        $self->validateLoadedConfig();
45
46
        return $self;
47
    }
48
}
49