Versioned   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A version() 0 3 1
A __construct() 0 4 1
A applyVersion() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tleckie\Assets\Versioned;
6
7
use function sprintf;
8
9
/**
10
 * Class Versioned
11
 *
12
 * @package  Tleckie\Assets\Versioned
13
 * @category Versioned
14
 * @author   Teodoro Leckie Westberg <[email protected]>
15
 */
16
class Versioned implements VersionedInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    protected string $version = '';
22
23
    /**
24
     * @var string
25
     */
26
    protected string $format = '';
27
28
    /**
29
     * Versioned constructor.
30
     *
31
     * @param string $version
32
     * @param string $format
33
     */
34
    public function __construct(string $version, string $format = "%s?%s")
35
    {
36
        $this->version = $version;
37
        $this->format = $format;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function applyVersion(string $asset): string
44
    {
45
        return preg_replace(
46
            '#\/{2,}#',
47
            '/',
48
            sprintf($this->format, $asset, $this->version())
49
        );
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function version(): string
56
    {
57
        return $this->version;
58
    }
59
}
60