Passed
Pull Request — master (#15)
by Enjoys
02:34
created

StrategyAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 50
ccs 12
cts 12
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateHashId() 0 5 1
A getHashId() 0 3 1
A __construct() 0 10 1
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