Passed
Push — main ( 8bfeba...683260 )
by Teodoro
01:57
created

JsonManifestVersioned::version()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tleckie\Assets\Versioned;
6
7
use InvalidArgumentException;
8
use JsonException;
9
use function file_get_contents;
10
use function json_decode;
11
12
/**
13
 * Class JsonManifestVersioned
14
 *
15
 * @package  Tleckie\Assets\Versioned
16
 * @category JsonManifestVersioned
17
 * @author   Teodoro Leckie Westberg <[email protected]>
18
 */
19
class JsonManifestVersioned implements VersionedInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    protected string $version = '';
25
26
    /**
27
     * @var string
28
     */
29
    protected string $format = '';
30
31
    /**
32
     * @var array
33
     */
34
    protected array $data;
35
36
    /**
37
     * JsonManifestVersioned constructor.
38
     *
39
     * @param string $manifestPath
40
     * @throws JsonException|InvalidArgumentException
41
     */
42
    public function __construct(string $manifestPath)
43
    {
44
        if (!is_file($manifestPath)) {
45
            throw new InvalidArgumentException(
46
                sprintf('File [%s] not found.', $manifestPath)
47
            );
48
        }
49
50
        $this->data = json_decode(
51
            file_get_contents($manifestPath),
52
            true,
53
            2,
54
            JSON_THROW_ON_ERROR
55
        );
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function version(): string
62
    {
63
        return '';
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69
    public function applyVersion(string $asset): string
70
    {
71
        if (isset($this->data[$asset])) {
72
            $asset = $this->data[$asset];
73
        }
74
75
        return $asset;
76
    }
77
}
78