Styles::getFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace kalanis\kw_styles;
4
5
6
use kalanis\kw_styles\Interfaces\ILoader;
7
8
9
/**
10
 * Class Styles
11
 * @package kalanis\kw_styles
12
 * Store styles wanted for rendering
13
 */
14
class Styles
15
{
16
    protected static ?ILoader $loader = null;
17
    /** @var array<string, array<int, string>> */
18
    protected static array $styles = [];
19
20 5
    public static function init(?ILoader $loader): void
21
    {
22 5
        static::$loader = $loader;
23 5
    }
24
25 1
    public static function want(string $module, string $path): void
26
    {
27 1
        if (empty(static::$styles[$module])) {
28 1
            static::$styles[$module] = [];
29
        }
30 1
        static::$styles[$module][] = $path;
31 1
    }
32
33
    /**
34
     * @return array<string, array<int, string>>
35
     */
36 1
    public static function getAll(): array
37
    {
38 1
        return static::$styles;
39
    }
40
41
    /**
42
     * @param string $module
43
     * @param string $path
44
     * @throws StylesException
45
     * @return string|null
46
     */
47 4
    public static function getFile(string $module, string $path): ?string
48
    {
49 4
        if (!static::$loader) {
50 1
            throw new StylesException('Set the loader first!');
51
        }
52 3
        return static::$loader->load($module, $path);
53
    }
54
}
55