Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
NewsUtils | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
getNewsFormatIcon | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
fromEnv | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\News\Utils; |
4 | |
5 | use Olz\Entity\News\NewsEntry; |
6 | use Olz\Utils\WithUtilsTrait; |
7 | |
8 | class NewsUtils { |
9 | use WithUtilsTrait; |
10 | |
11 | /** @var array<string, string> */ |
12 | protected static $iconBasenameByFormat = [ |
13 | 'aktuell' => 'entry_type_aktuell_20.svg', |
14 | 'forum' => 'entry_type_forum_20.svg', |
15 | 'galerie' => 'entry_type_gallery_20.svg', |
16 | 'kaderblog' => 'entry_type_kaderblog_20.svg', |
17 | 'video' => 'entry_type_movie_20.svg', |
18 | |
19 | 'galerie_white' => 'entry_type_gallery_white_20.svg', |
20 | 'video_white' => 'entry_type_movie_white_20.svg', |
21 | ]; |
22 | |
23 | public function getNewsFormatIcon( |
24 | NewsEntry|string $input, |
25 | ?string $modifier = null, |
26 | ): ?string { |
27 | $format = $input instanceof NewsEntry ? $input->getFormat() : $input; |
28 | $key = $modifier === null ? $format : "{$format}_{$modifier}"; |
29 | $icon = self::$iconBasenameByFormat[$key] ?? null; |
30 | if ($icon === null) { |
31 | return null; |
32 | } |
33 | $code_href = $this->envUtils()->getCodeHref(); |
34 | return "{$code_href}assets/icns/{$icon}"; |
35 | } |
36 | |
37 | public static function fromEnv(): self { |
38 | return new self(); |
39 | } |
40 | } |