Passed
Pull Request — master (#61)
by Jesús
22:49
created

GacelaConfigItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 7
eloc 26
c 0
b 0
f 0
dl 0
loc 67
rs 10
ccs 21
cts 27
cp 0.7778

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 13 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
    /**
19
     * @param array<array-key, mixed> $item
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, mixed> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, mixed>.
Loading history...
20
     */
21 5
    public static function fromArray(array $item): self
22
    {
23
        /** @var null|string $type */
24 5
        $type = $item['type'] ?? null;
25
        /** @var null|string $path */
26 5
        $path = $item['path'] ?? null;
27
        /** @var null|string $pathLocal */
28 5
        $pathLocal = $item['path_local'] ?? null;
29
30 5
        return new self(
31 5
            $type ?? self::DEFAULT_TYPE,
32 5
            $path ?? self::DEFAULT_PATH,
33 5
            $pathLocal ?? self::DEFAULT_PATH_LOCAL
34
        );
35
    }
36
37 15
    public static function withDefaults(): self
38
    {
39 15
        return new self();
40
    }
41
42 20
    private function __construct(
43
        string $type = self::DEFAULT_TYPE,
44
        string $path = self::DEFAULT_PATH,
45
        string $pathLocal = self::DEFAULT_PATH_LOCAL
46
    ) {
47 20
        $this->type = $type;
48 20
        $this->path = $path;
49 20
        $this->pathLocal = $pathLocal;
50 20
    }
51
52 20
    public function type(): string
53
    {
54 20
        return $this->type;
55
    }
56
57 20
    public function path(): string
58
    {
59 20
        return $this->path;
60
    }
61
62 20
    public function pathLocal(): string
63
    {
64 20
        return $this->pathLocal;
65
    }
66
67
    public function __toString(): string
68
    {
69
        return sprintf(
70
            'GacelaConfigItem{ type:%s, path:%s, pathLocal:%s }',
71
            $this->type,
72
            $this->path,
73
            $this->pathLocal
74
        );
75
    }
76
}
77