Completed
Push — master ( 2b133d...acf90e )
by Michal
05:36
created

Revision::isVersionHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Webrouse\AssetMacro;
5
6
7
use Nette\Utils\Strings;
8
9
class Revision
10
{
11
	/** @var Config */
12
	private $config;
13
14
	/** @var string */
15
	private $assetPath;
16
17
	/** @var string */
18
	private $rawValue;
19
20
	/** @var bool */
21
	private $isVersion;
22
23
	/** @var string */
24
	private $relativePath;
25
26
	/** @var string */
27
	private $absolutePath;
28
29
	/** @var string */
30
	private $relativeUrl;
31
32
33 1
	public function __construct(Config $config, string $assetPath, ?string $revision)
34
	{
35 1
		$this->config = $config;
36 1
		$this->assetPath = $assetPath;
37 1
		$this->rawValue = $revision ?: 'unknown';
38
39
		// Is revision only version (query parameter) or full path to asset?
40 1
		$this->isVersion = $revision === null || !Strings::match((string) $revision, '/[.\/]/');
41
42 1
		$this->relativePath = ($this->isVersion ? $this->assetPath : Utils::normalizePath($revision));
43 1
		$this->absolutePath = $this->config->getAssetsPath() . DIRECTORY_SEPARATOR . $this->relativePath;
44 1
		$this->relativeUrl = $this->isVersion ? ($this->assetPath . '?v=' . $this->rawValue) : $revision;
45 1
	}
46
47
48
	public function getRawValue(): string
49
	{
50 1
		return $this->rawValue;
51
	}
52
53
54
	public function isVersionHash(): bool
55
	{
56
		return $this->isVersion;
57
	}
58
59
60
	public function getAssetPath(): string
61
	{
62
		return $this->assetPath;
63
	}
64
65
66
	public function getRelativePath(): string
67
	{
68 1
		return $this->relativePath;
69
	}
70
71
72
	public function getAbsolutePath(): string
73
	{
74 1
		return $this->absolutePath;
75
	}
76
77
78
	public function getRelativeUrl(): string
79
	{
80 1
		return $this->relativeUrl;
81
	}
82
}
83