Test Failed
Push — master ( 93d5dd...ff9b8c )
by Julien
04:21
created

ModelsMap::getGroupClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 1
f 0
ccs 1
cts 1
cp 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Support;
13
14
use Phalcon\Di\DiInterface;
15
use Phalcon\Mvc\ModelInterface;
16
use Zemit\Bootstrap\Config;
17
use Zemit\Models\Backup;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\Backup was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Zemit\Models\Audit;
19
use Zemit\Models\AuditDetail;
20
use Zemit\Models\Log;
21
use Zemit\Models\Email;
22
use Zemit\Models\Job;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\Job was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Zemit\Models\File;
24
use Zemit\Models\Session;
25
use Zemit\Models\Flag;
26
use Zemit\Models\Setting;
27
use Zemit\Models\Lang;
28
use Zemit\Models\Translate;
29
use Zemit\Models\TranslateField;
30
use Zemit\Models\TranslateTable;
31
use Zemit\Models\Site;
32
use Zemit\Models\SiteLang;
33
use Zemit\Models\Page;
34
use Zemit\Models\Post;
35
use Zemit\Models\Template;
36
use Zemit\Models\Channel;
37
use Zemit\Models\Field;
38
use Zemit\Models\Profile;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\Profile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use Zemit\Models\User;
40
use Zemit\Models\UserType;
41
use Zemit\Models\UserGroup;
42
use Zemit\Models\UserRole;
43
use Zemit\Models\UserFeature;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\UserFeature was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
use Zemit\Models\Role;
45
use Zemit\Models\RoleRole;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\RoleRole was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
use Zemit\Models\RoleFeature;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\RoleFeature was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
use Zemit\Models\Group;
48
use Zemit\Models\GroupRole;
49
use Zemit\Models\GroupType;
50
use Zemit\Models\GroupFeature;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\GroupFeature was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
use Zemit\Models\Type;
52
use Zemit\Models\Feature;
0 ignored issues
show
Bug introduced by
The type Zemit\Models\Feature was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
53
54
/**
55
 * Allow to get mapped classes without using magic methods
56
 */
57
trait ModelsMap
58
{
59
    /**
60
     * Store an array of mapped models
61
     */
62
    public ?array $modelsMap = null;
63
    
64
    abstract public function getDI(): DiInterface;
65
    
66
    /**
67
     * Retrieve the config from DI
68
     */
69
    public function getConfig(): Config
70
    {
71
        return $this->getDI()->get('config');
72 1
    }
73
    
74 1
    /**
75
     * Get an array of mapped models
76
     */
77
    public function getModelsMap(): array
78
    {
79
        if (!isset($this->modelsMap)) {
80
            $this->setModelsMap();
81 1
        }
82
        return $this->modelsMap;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->modelsMap could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
83 1
    }
84 1
    
85
    /**
86 1
     * Set the models mapping or retrieve the mapped models from the config
87
     */
88
    public function setModelsMap(?array $modelsMap = null): void
89
    {
90
        $this->modelsMap = $modelsMap ?? $this->getConfig()->pathToArray('models') ?? [];
91
    }
92
    
93
    /**
94 1
     * Map a new class
95
     */
96 1
    public function setClassMap(string $map, ?string $class): void
97
    {
98
        $this->modelsMap[$map] = $class;
99
    }
100 1
    
101 1
    /**
102
     * Remove an existing class
103
     */
104
    public function removeClassMap(string $map): void
105
    {
106
        unset($this->modelsMap[$map]);
107
    }
108
    
109
    /**
110 1
     * Return the class mapping
111
     */
112 1
    public function getClassMap(string $class): string
113
    {
114
        return $this->getModelsMap()[$class] ?? $class;
115
    }
116
    
117
    /**
118
     * Return an instance of the class
119 1
     */
120
    public function getObjectMap(string $class): ModelInterface
121 1
    {
122
        $class = $this->getClassMap($class);
123
        return new $class();
124
    }
125
    
126
    /**
127
     * Return the mapped class name of \Zemit\Models\Backup::class
128 1
     */
129
    public function getBackupClass(): string
130 1
    {
131
        return $this->getClassMap(Backup::class);
132
    }
133
    
134
    /**
135
     * Return the mapped class name of \Zemit\Models\Audit::class
136
     */
137 1
    public function getAuditClass(): string
138
    {
139 1
        return $this->getClassMap(Audit::class);
140
    }
141
    
142
    /**
143
     * Return the mapped class name of \Zemit\Models\AuditDetail::class
144
     */
145
    public function getAuditDetailClass(): string
146 1
    {
147
        return $this->getClassMap(AuditDetail::class);
148 1
    }
149
    
150
    /**
151
     * Return the mapped class name of \Zemit\Models\Log::class
152
     */
153
    public function getLogClass(): string
154
    {
155 1
        return $this->getClassMap(Log::class);
156
    }
157 1
    
158
    /**
159
     * Return the mapped class name of \Zemit\Models\Email::class
160
     */
161
    public function getEmailClass(): string
162
    {
163
        return $this->getClassMap(Email::class);
164 1
    }
165
    
166 1
    /**
167
     * Return the mapped class name of \Zemit\Models\Job::class
168
     */
169
    public function getJobClass(): string
170
    {
171
        return $this->getClassMap(Job::class);
172
    }
173 1
    
174
    /**
175 1
     * Return the mapped class name of \Zemit\Models\File::class
176
     */
177
    public function getFileClass(): string
178
    {
179
        return $this->getClassMap(File::class);
180
    }
181
    
182 1
    /**
183
     * Return the mapped class name of \Zemit\Models\Session::class
184 1
     */
185
    public function getSessionClass(): string
186
    {
187
        return $this->getClassMap(Session::class);
188
    }
189
    
190
    /**
191 1
     * Return the mapped class name of \Zemit\Models\Flag::class
192
     */
193 1
    public function getFlagClass(): string
194
    {
195
        return $this->getClassMap(Flag::class);
196
    }
197
    
198
    /**
199
     * Return the mapped class name of \Zemit\Models\Setting::class
200 1
     */
201
    public function getSettingClass(): string
202 1
    {
203
        return $this->getClassMap(Setting::class);
204
    }
205
    
206
    /**
207
     * Return the mapped class name of \Zemit\Models\Lang::class
208
     */
209 1
    public function getLangClass(): string
210
    {
211 1
        return $this->getClassMap(Lang::class);
212
    }
213
    
214
    /**
215
     * Return the mapped class name of \Zemit\Models\Translate::class
216
     */
217
    public function getTranslateClass(): string
218 1
    {
219
        return $this->getClassMap(Translate::class);
220 1
    }
221
    
222
    /**
223
     * Return the mapped class name of \Zemit\Models\TranslateField::class
224
     */
225
    public function getTranslateFieldClass(): string
226
    {
227 1
        return $this->getClassMap(TranslateField::class);
228
    }
229 1
    
230
    /**
231
     * Return the mapped class name of \Zemit\Models\TranslateTable::class
232
     */
233
    public function getTranslateTableClass(): string
234
    {
235
        return $this->getClassMap(TranslateTable::class);
236 1
    }
237
    
238 1
    /**
239
     * Return the mapped class name of \Zemit\Models\Site::class
240
     */
241
    public function getSiteClass(): string
242
    {
243
        return $this->getClassMap(Site::class);
244
    }
245 1
    
246
    /**
247 1
     * Return the mapped class name of \Zemit\Models\SiteLang::class
248
     */
249
    public function getSiteLangClass(): string
250
    {
251
        return $this->getClassMap(SiteLang::class);
252
    }
253
    
254 1
    /**
255
     * Return the mapped class name of \Zemit\Models\Page::class
256 1
     */
257
    public function getPageClass(): string
258
    {
259
        return $this->getClassMap(Page::class);
260
    }
261
    
262
    /**
263 1
     * Return the mapped class name of \Zemit\Models\Post::class
264
     */
265 1
    public function getPostClass(): string
266
    {
267
        return $this->getClassMap(Post::class);
268
    }
269
    
270
    /**
271
     * Return the mapped class name of \Zemit\Models\Template::class
272 1
     */
273
    public function getTemplateClass(): string
274 1
    {
275
        return $this->getClassMap(Template::class);
276
    }
277
    
278
    /**
279
     * Return the mapped class name of \Zemit\Models\Channel::class
280
     */
281 1
    public function getChannelClass(): string
282
    {
283 1
        return $this->getClassMap(Channel::class);
284
    }
285
    
286
    /**
287
     * Return the mapped class name of \Zemit\Models\Field::class
288
     */
289
    public function getFieldClass(): string
290 1
    {
291
        return $this->getClassMap(Field::class);
292 1
    }
293
    
294
    /**
295
     * Return the mapped class name of \Zemit\Models\Profile::class
296
     */
297
    public function getProfileClass(): string
298
    {
299 1
        return $this->getClassMap(Profile::class);
300
    }
301 1
    
302
    /**
303
     * Return the mapped class name of \Zemit\Models\User::class
304
     */
305
    public function getUserClass(): string
306
    {
307
        return $this->getClassMap(User::class);
308 1
    }
309
    
310 1
    /**
311
     * Return the mapped class name of \Zemit\Models\UserType::class
312
     */
313
    public function getUserTypeClass(): string
314
    {
315
        return $this->getClassMap(UserType::class);
316
    }
317 1
    
318
    /**
319 1
     * Return the mapped class name of \Zemit\Models\UserGroup::class
320
     */
321
    public function getUserGroupClass(): string
322
    {
323
        return $this->getClassMap(UserGroup::class);
324
    }
325
    
326 1
    /**
327
     * Return the mapped class name of \Zemit\Models\UserRole::class
328 1
     */
329
    public function getUserRoleClass(): string
330
    {
331
        return $this->getClassMap(UserRole::class);
332
    }
333
    
334
    /**
335 1
     * Return the mapped class name of \Zemit\Models\UserFeature::class
336
     */
337 1
    public function getUserFeatureClass(): string
338
    {
339
        return $this->getClassMap(UserFeature::class);
340
    }
341
    
342
    /**
343
     * Return the mapped class name of \Zemit\Models\Role::class
344 1
     */
345
    public function getRoleClass(): string
346 1
    {
347
        return $this->getClassMap(Role::class);
348
    }
349
    
350
    /**
351
     * Return the mapped class name of \Zemit\Models\RoleRole::class
352
     */
353 1
    public function getRoleRoleClass(): string
354
    {
355 1
        return $this->getClassMap(RoleRole::class);
356
    }
357
    
358
    /**
359
     * Return the mapped class name of \Zemit\Models\RoleFeature::class
360
     */
361
    public function getRoleFeatureClass(): string
362 1
    {
363
        return $this->getClassMap(RoleFeature::class);
364 1
    }
365
    
366
    /**
367
     * Return the mapped class name of \Zemit\Models\Group::class
368
     */
369
    public function getGroupClass(): string
370
    {
371 1
        return $this->getClassMap(Group::class);
372
    }
373 1
    
374
    /**
375
     * Return the mapped class name of \Zemit\Models\GroupRole::class
376
     */
377
    public function getGroupRoleClass(): string
378
    {
379
        return $this->getClassMap(GroupRole::class);
380 1
    }
381
    
382 1
    /**
383
     * Return the mapped class name of \Zemit\Models\GroupType::class
384
     */
385
    public function getGroupTypeClass(): string
386
    {
387
        return $this->getClassMap(GroupType::class);
388
    }
389 1
    
390
    /**
391 1
     * Return the mapped class name of \Zemit\Models\GroupFeature::class
392
     */
393
    public function getGroupFeatureClass(): string
394
    {
395
        return $this->getClassMap(GroupFeature::class);
396
    }
397
    
398 1
    /**
399
     * Return the mapped class name of \Zemit\Models\Type::class
400 1
     */
401
    public function getTypeClass(): string
402
    {
403
        return $this->getClassMap(Type::class);
404
    }
405
    
406
    /**
407 1
     * Return the mapped class name of \Zemit\Models\Feature::class
408
     */
409 1
    public function getFeatureClass(): string
410
    {
411
        return $this->getClassMap(Feature::class);
412
    }
413
}
414