Completed
Pull Request — master (#86)
by Vladimir
31:16
created

AssetEngineManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 72.21%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 48
ccs 13
cts 18
cp 0.7221
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addAssetEngines() 0 7 2
A addAssetEngine() 0 13 2
A getEngines() 0 4 1
A getEngineByExtension() 0 9 2
A getFoldersToWatch() 0 4 1
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\AssetEngine;
9
10
use allejo\stakx\Exception\UnsupportedAssetEngineException;
11
12
class AssetEngineManager
13
{
14
    private $enginesByExtension = [];
15
    private $foldersToWatch = [];
16
    private $engines;
17
18
    public function addAssetEngines(/* iterable */ $assetEngines)
19
    {
20
        foreach ($assetEngines as $assetEngine)
21
        {
22
            $this->addAssetEngine($assetEngine);
23
        }
24
    }
25
26 7
    public function addAssetEngine(AssetEngineInterface $assetEngine)
27
    {
28 7
        $extensions = $assetEngine->getExtensions();
29
30 7
        $e = $this->engines[] = $assetEngine;
31
32 7
        foreach ($extensions as $extension)
33
        {
34 7
            $this->enginesByExtension[$extension] = $e;
35
        }
36
37 7
        $this->foldersToWatch[$assetEngine->getFolder()] = $e;
38 7
    }
39
40 7
    public function getEngines()
41
    {
42 7
        return $this->engines;
43
    }
44
45 6
    public function getEngineByExtension($extension)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
46
    {
47 6
        if (isset($this->enginesByExtension[$extension]))
48
        {
49 6
            return $this->enginesByExtension[$extension];
50
        }
51
52
        throw new UnsupportedAssetEngineException($extension, "There is no support to handle the '${extension}' asset type.");
53
    }
54
55
    public function getFoldersToWatch()
56
    {
57 1
        return $this->foldersToWatch;
58
    }
59
}
60