Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
WithUtilsTrait
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
9 / 9
10
100.00% covered (success)
100.00%
1 / 1
 getParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createGetParams
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setGetParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 server
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createServer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setServer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAllUtils
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAllUtils
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOrCreate
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Olz\Utils;
4
5use Olz\Anniversary\Utils\AnniversaryUtilsTrait;
6use Olz\Captcha\Utils\CaptchaUtilsTrait;
7use Olz\Fetchers\SolvFetcherTrait;
8use Olz\News\Utils\NewsUtilsTrait;
9use Olz\Suche\Utils\SearchUtilsTrait;
10use Olz\Termine\Utils\TermineUtilsTrait;
11
12trait WithUtilsTrait {
13    use AnniversaryUtilsTrait;
14    use AuthUtilsTrait;
15    use CaptchaUtilsTrait;
16    use DateUtilsTrait;
17    use DbUtilsTrait;
18    use DevDataUtilsTrait;
19    use EmailUtilsTrait;
20    use EntityManagerTrait;
21    use EntityUtilsTrait;
22    use EnvUtilsTrait;
23    use GeneralUtilsTrait;
24    use HtmlUtilsTrait;
25    use HttpUtilsTrait;
26    use IdUtilsTrait;
27    use ImageUtilsTrait;
28    use LogTrait;
29    use MapUtilsTrait;
30    use MailerTrait;
31    use MessageBusTrait;
32    use NewsUtilsTrait;
33    use SearchUtilsTrait;
34    use SessionTrait;
35    use SolvFetcherTrait;
36    use StravaUtilsTrait;
37    use SymfonyUtilsTrait;
38    use TelegramUtilsTrait;
39    use TermineUtilsTrait;
40    use UploadUtilsTrait;
41
42    // Legacy implementation
43    // TODO: Migrate away!
44
45    /**
46     * @return array<string, string>
47     */
48    public function getParams(): array {
49        return $this->getOrCreate('getParams');
50    }
51
52    /**
53     * @return array<string, string>
54     */
55    public function createGetParams(): array {
56        global $_GET;
57        return $_GET;
58    }
59
60    /**
61     * @param array<string, string> $getParams
62     */
63    public function setGetParams(array $getParams): void {
64        WithUtilsCache::set('getParams', $getParams);
65    }
66
67    /**
68     * @return array<string, mixed>
69     */
70    public function server(): array {
71        return $this->getOrCreate('server');
72    }
73
74    /**
75     * @return array<string, mixed>
76     */
77    public function createServer(): array {
78        global $_SERVER;
79        return $_SERVER;
80    }
81
82    /**
83     * @param array<string, mixed> $server
84     */
85    public function setServer(array $server): void {
86        WithUtilsCache::set('server', $server);
87    }
88
89    // ---
90
91    /**
92     * @return array<string, mixed>
93     */
94    public function getAllUtils(): array {
95        return WithUtilsCache::getAll();
96    }
97
98    /**
99     * @param array<string, mixed> $all_utils
100     */
101    public function setAllUtils(array $all_utils): void {
102        WithUtilsCache::setAll($all_utils);
103    }
104
105    protected function getOrCreate(string $util_name): mixed {
106        $util = WithUtilsCache::get($util_name);
107        if ($util) {
108            return $util;
109        }
110        $cap_util_name = ucfirst($util_name);
111        $creator_name = "create{$cap_util_name}";
112        $util = $this->{$creator_name}();
113        WithUtilsCache::set($util_name, $util);
114        return $util;
115    }
116}