Config   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 96.55%

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 2
dl 0
loc 127
ccs 28
cts 29
cp 0.9655
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 24 5
A isCacheEnabled() 0 4 1
A getManifestAsArray() 0 4 1
A getManifestPath() 0 4 1
A getManifestAutodetectPaths() 0 4 1
A getAssetsPath() 0 4 1
A getPublicPath() 0 4 1
A getMissingAssetPolicy() 0 4 1
A getMissingManifestPolicy() 0 4 1
A getMissingRevisionPolicy() 0 4 1
A getDefaultFormat() 0 4 1
A getHash() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Webrouse\AssetMacro;
5
6
7
use Nette\Utils\FileSystem;
8
use Webrouse\AssetMacro\Exceptions\InvalidPathException;
9
10
class Config
11
{
12
	/** @var bool */
13
	private $cacheEnabled;
14
15
	/** @var array|null */
16
	private $manifestAsArray;
17
18
	/** @var string|null */
19
	private $manifestPath;
20
21
	/** @var array */
22
	private $manifestAutodetectPaths;
23
24
	/** @var string|null */
25
	private $assetsPath;
26
27
	/** @var string */
28
	private $publicPath;
29
30
	/** @var string */
31
	private $missingAssetPolicy;
32
33
	/** @var string */
34
	private $missingManifestPolicy;
35
36
	/** @var string */
37
	private $missingRevisionPolicy;
38
39
	/** @var string */
40
	private $defaultFormat;
41
42
	/** @var string */
43
	private $hash;
44
45
46 1
	public function __construct(array $config)
47
	{
48 1
		$this->cacheEnabled = $config['cache'];
49 1
		$this->manifestAsArray = is_array($config['manifest']) ? $config['manifest'] : null;
50 1
		$this->manifestPath = !$this->manifestAsArray ? $config['manifest'] : null;
51 1
		$this->manifestAutodetectPaths = $config['autodetect'];
52 1
		$this->assetsPath = $config['assetsPath'];
53 1
		$this->publicPath = $config['publicPath'];
54 1
		$this->missingAssetPolicy = $config['missingAsset'];
55 1
		$this->missingManifestPolicy = $config['missingManifest'];
56 1
		$this->missingRevisionPolicy = $config['missingRevision'];
57 1
		$this->defaultFormat = $config['format'];
58 1
		$this->hash = md5(serialize($config));
59
60
		// Normalize paths
61 1
		$this->assetsPath = Utils::normalizePath($this->assetsPath);
62 1
		$this->publicPath = Utils::normalizePath(trim($this->publicPath, '/'));
63 1
		$this->publicPath = $this->publicPath ? ($this->publicPath . '/') : '';
64
65
		// Assets path must be absolute
66 1
		if (!FileSystem::isAbsolute($config['assetsPath'])) {
67
			throw new InvalidPathException('Asset macro: assetsPath must be absolute.');
68
		}
69 1
	}
70
71
72
	public function isCacheEnabled(): bool
73
	{
74 1
		return $this->cacheEnabled;
75
	}
76
77
78
	public function getManifestAsArray(): ?array
79
	{
80 1
		return $this->manifestAsArray;
81
	}
82
83
84
	public function getManifestPath(): ?string
85
	{
86 1
		return $this->manifestPath;
87
	}
88
89
90
	public function getManifestAutodetectPaths(): array
91
	{
92 1
		return $this->manifestAutodetectPaths;
93
	}
94
95
96
	public function getAssetsPath(): string
97
	{
98 1
		return $this->assetsPath;
99
	}
100
101
102
	public function getPublicPath(): string
103
	{
104 1
		return $this->publicPath;
105
	}
106
107
108
	public function getMissingAssetPolicy(): string
109
	{
110 1
		return $this->missingAssetPolicy;
111
	}
112
113
114
	public function getMissingManifestPolicy(): string
115
	{
116 1
		return $this->missingManifestPolicy;
117
	}
118
119
120
	public function getMissingRevisionPolicy(): string
121
	{
122 1
		return $this->missingRevisionPolicy;
123
	}
124
125
126
	public function getDefaultFormat(): string
127
	{
128 1
		return $this->defaultFormat;
129
	}
130
131
132
	public function getHash(): string
133
	{
134 1
		return $this->hash;
135
	}
136
}
137