Scripts::getAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_scripts;
4
5
6
use kalanis\kw_scripts\Interfaces\ILoader;
7
8
9
/**
10
 * Class Scripts
11
 * @package kalanis\kw_scripts
12
 * Store wanted scripts for rendering
13
 */
14
class Scripts
15
{
16
    protected static ?ILoader $loader = null;
17
    /** @var array<string, array<int, string>> */
18
    protected static array $scripts = [];
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::$scripts[$module])) {
28 1
            static::$scripts[$module] = [];
29
        }
30 1
        static::$scripts[$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::$scripts;
39
    }
40
41
    /**
42
     * @param string $module
43
     * @param string $path
44
     * @throws ScriptsException
45
     * @return string|null
46
     */
47 4
    public static function getFile(string $module, string $path): ?string
48
    {
49 4
        if (is_null(static::$loader)) {
50 1
            throw new ScriptsException('Set the loader first!');
51
        }
52 3
        return static::$loader->load($module, $path);
53
    }
54
}
55