Passed
Push — master ( 59589b...c79df9 )
by Enjoys
05:41 queued 03:11
created

StrategyAbstract::getHashId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Enjoys\AssetsCollector\CollectStrategy;
4
5
use Enjoys\AssetsCollector\Asset;
6
use Enjoys\AssetsCollector\Environment;
7
use Psr\Log\LoggerInterface;
8
9
abstract class StrategyAbstract implements StrategyInterface
10
{
11
    /**
12
     * @var Asset[]
13
     */
14
    protected array $assets;
15
16
    protected string $hashId;
17
18
    /**
19
     * @var string css or js
20
     */
21
    protected string $type;
22
23
    /**
24
     * @var Environment
25
     */
26
    protected Environment $environment;
27
28
    protected LoggerInterface $logger;
29
30
31
    /**
32
     * StrategyAbstract constructor.
33
     * @param Environment $environment
34
     * @param array<Asset> $assets
35
     * @param string $type
36
     */
37 17
    public function __construct(
38
        Environment $environment,
39
        array $assets,
40
        string $type
41
    ) {
42 17
        $this->environment = $environment;
43 17
        $this->assets = $assets;
44 17
        $this->hashId = $this->generateHashId();
45 17
        $this->type = $type;
46 17
        $this->logger = $environment->getLogger();
47
    }
48
49 17
    private function generateHashId(): string
50
    {
51 17
        $assetsIds = array_keys($this->assets);
52 17
        sort($assetsIds);
53 17
        return md5(implode('', $assetsIds));
54
    }
55
56 4
    public function getHashId(): string
57
    {
58 4
        return $this->hashId;
59
    }
60
61
}
62