Completed
Pull Request — master (#69)
by Vladimir
02:48
created

AssetEngineManager::addAssetEngine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\AssetEngine;
9
10
use __;
11
use allejo\stakx\Exception\UnsupportedAssetEngineException;
12
13
class AssetEngineManager
14
{
15
    private $enginesByExtension = [];
16
    private $foldersToWatch = [];
17
    private $engines;
18
19
    public function addAssetEngines(/* iterable */ $assetEngines)
20
    {
21
        foreach ($assetEngines as $assetEngine)
22
        {
23
            $this->addAssetEngine($assetEngine);
24
        }
25
    }
26
27 4
    public function addAssetEngine(AssetEngineInterface $assetEngine)
28
    {
29 4
        $extensions = $assetEngine->getExtensions();
30
31 4
        $e = $this->engines[] = $assetEngine;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
32
33 4
        foreach ($extensions as $extension)
34
        {
35 4
            $this->enginesByExtension[$extension] = $e;
36
        }
37
38 4
        $this->foldersToWatch[$assetEngine->getFolder()] = $e;
39 4
    }
40
41 4
    public function getEngines()
42
    {
43 4
        return $this->engines;
44
    }
45
46 4
    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...
47
    {
48 4
        if (isset($this->enginesByExtension[$extension]))
49
        {
50 4
            return $this->enginesByExtension[$extension];
51
        }
52
53
        throw new UnsupportedAssetEngineException($extension, 'There is no support to handle this asset type.');
54
    }
55
56
    public function getFoldersToWatch()
57
    {
58
        return $this->foldersToWatch;
59
    }
60
}
61