Total Complexity | 11 |
Total Lines | 65 |
Duplicated Lines | 0 % |
Coverage | 85.71% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
13 | class AssetSource |
||
14 | { |
||
15 | use SingletonTrait; |
||
16 | |||
17 | /** |
||
18 | * @param $source |
||
19 | * @param $type |
||
20 | * @return string |
||
21 | 9 | */ |
|
22 | public static function check($source, $type) |
||
23 | { |
||
24 | 4 | return function () use ($source, $type) { |
|
|
|||
25 | 9 | return static::instance()->buildSource($source, $type); |
|
26 | }; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param $source |
||
31 | * @param $type |
||
32 | * @return string |
||
33 | 7 | */ |
|
34 | protected function buildSource($source, $type) |
||
35 | 7 | { |
|
36 | 1 | if (empty($source)) { |
|
37 | return $source; |
||
38 | 6 | } |
|
39 | 4 | if ($this->isFullPath($source)) { |
|
40 | return $source; |
||
41 | 2 | } |
|
42 | 1 | if ($type === Asset::TYPE_STYLES) { |
|
43 | return $this->transformSourceWithAsset('/stylesheets/'.$source.'.css'); |
||
44 | 1 | } |
|
45 | 1 | if ($type === Asset::TYPE_SCRIPTS) { |
|
46 | return $this->transformSourceWithAsset('/scripts/'.$source.'.js'); |
||
47 | } |
||
48 | |||
49 | return $source; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param $source |
||
54 | * @return bool |
||
55 | 6 | */ |
|
56 | protected function isFullPath($source) |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param $source |
||
73 | * @return string |
||
74 | */ |
||
75 | protected function transformSourceWithAsset($source) |
||
78 | } |
||
79 | } |
||
80 |