Completed
Push — master ( 5bbfc4...6ddfd6 )
by Vladimir
02:33
created

AssetEngineManager::getEngineByExtension()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 3
cts 4
cp 0.75
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0625
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