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