Passed
Pull Request — master (#54)
by Jesús
02:44
created

GacelaConfigItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 57
rs 10
c 0
b 0
f 0
ccs 18
cts 24
cp 0.75
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A pathLocal() 0 3 1
A __toString() 0 7 1
A withDefaults() 0 3 1
A path() 0 3 1
A fromArray() 0 6 1
A type() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config\GacelaFileConfig;
6
7
final class GacelaConfigItem
8
{
9
    public const DEFAULT_TYPE = 'php';
10
11
    private const DEFAULT_PATH = 'config/*.php';
12
    private const DEFAULT_PATH_LOCAL = 'config/local.php';
13
14
    private string $type;
15
    private string $path;
16
    private string $pathLocal;
17
18 5
    public static function fromArray(array $json): self
19
    {
20 5
        return new self(
21 5
            (string)($json['type'] ?? self::DEFAULT_TYPE),
22 5
            (string)($json['path'] ?? self::DEFAULT_PATH),
23 5
            (string)($json['path_local'] ?? self::DEFAULT_PATH_LOCAL)
24
        );
25
    }
26
27 15
    public static function withDefaults(): self
28
    {
29 15
        return new self();
30
    }
31
32 20
    private function __construct(
33
        string $type = self::DEFAULT_TYPE,
34
        string $path = self::DEFAULT_PATH,
35
        string $pathLocal = self::DEFAULT_PATH_LOCAL
36
    ) {
37 20
        $this->type = $type;
38 20
        $this->path = $path;
39 20
        $this->pathLocal = $pathLocal;
40 20
    }
41
42 20
    public function type(): string
43
    {
44 20
        return $this->type;
45
    }
46
47 20
    public function path(): string
48
    {
49 20
        return $this->path;
50
    }
51
52 20
    public function pathLocal(): string
53
    {
54 20
        return $this->pathLocal;
55
    }
56
57
    public function __toString(): string
58
    {
59
        return sprintf(
60
            'GacelaJsonConfigItem{ type:%s, path:%s, pathLocal:%s }',
61
            $this->type,
62
            $this->path,
63
            $this->pathLocal
64
        );
65
    }
66
}
67