Passed
Push — master ( 889c24...e8b07e )
by Jesús
01:15 queued 11s
created

GacelaJsonConfigItem::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 0
cts 6
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config;
6
7
final class GacelaJsonConfigItem
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 7
    public static function withDefaults(): self
28
    {
29 7
        return new self();
30
    }
31
32 12
    private function __construct(
33
        string $type = self::DEFAULT_TYPE,
34
        string $path = self::DEFAULT_PATH,
35
        string $pathLocal = self::DEFAULT_PATH_LOCAL
36
    ) {
37 12
        $this->type = $type;
38 12
        $this->path = $path;
39 12
        $this->pathLocal = $pathLocal;
40 12
    }
41
42 12
    public function type(): string
43
    {
44 12
        return $this->type;
45
    }
46
47 12
    public function path(): string
48
    {
49 12
        return $this->path;
50
    }
51
52 12
    public function pathLocal(): string
53
    {
54 12
        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