Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
8 / 12 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Extras | |
66.67% |
8 / 12 |
|
83.33% |
5 / 6 |
7.33 | |
0.00% |
0 / 1 |
| addCss | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addJs | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| css | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scripts | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| moduleScripts | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| urls | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Panel; |
| 6 | |
| 7 | /** |
| 8 | * Additional stylesheets and scripts plugins inject into the panel |
| 9 | * chrome. Field controls load lazily via element descriptors instead; |
| 10 | * this is for app-wide assets. |
| 11 | */ |
| 12 | final class Extras |
| 13 | { |
| 14 | /** @var list<string> */ |
| 15 | private array $css = []; |
| 16 | |
| 17 | /** @var list<array{url: string, module: bool}> */ |
| 18 | private array $js = []; |
| 19 | |
| 20 | public function addCss(string $url): void |
| 21 | { |
| 22 | $this->css[] = $url; |
| 23 | } |
| 24 | |
| 25 | public function addJs(string $url, bool $module = true): void |
| 26 | { |
| 27 | $this->js[] = [ |
| 28 | 'url' => $url, |
| 29 | 'module' => $module, |
| 30 | ]; |
| 31 | } |
| 32 | |
| 33 | /** @return list<string> */ |
| 34 | public function css(): array |
| 35 | { |
| 36 | return $this->css; |
| 37 | } |
| 38 | |
| 39 | /** @return list<string> */ |
| 40 | public function scripts(): array |
| 41 | { |
| 42 | return $this->urls(false); |
| 43 | } |
| 44 | |
| 45 | /** @return list<string> */ |
| 46 | public function moduleScripts(): array |
| 47 | { |
| 48 | return $this->urls(true); |
| 49 | } |
| 50 | |
| 51 | /** @return list<string> */ |
| 52 | private function urls(bool $module): array |
| 53 | { |
| 54 | return array_values(array_map( |
| 55 | static fn(array $script): string => $script['url'], |
| 56 | array_filter($this->js, static fn(array $script): bool => $script['module'] === $module), |
| 57 | )); |
| 58 | } |
| 59 | } |