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