Test Failed
Push — master ( 62e8aa...e74fb5 )
by Julien
04:23
created

ModelsMap::getUserFeatureClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Support;
12
13
use Phalcon\Di\DiInterface;
14
use Zemit\Bootstrap\Config;
15
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...
16
use Zemit\Models\Audit;
17
use Zemit\Models\AuditDetail;
18
use Zemit\Models\Log;
19
use Zemit\Models\Email;
20
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...
21
use Zemit\Models\File;
22
use Zemit\Models\Session;
23
use Zemit\Models\Flag;
24
use Zemit\Models\Setting;
25
use Zemit\Models\Lang;
26
use Zemit\Models\Translate;
27
use Zemit\Models\TranslateField;
28
use Zemit\Models\TranslateTable;
29
use Zemit\Models\Site;
30
use Zemit\Models\SiteLang;
31
use Zemit\Models\Page;
32
use Zemit\Models\Post;
33
use Zemit\Models\Template;
34
use Zemit\Models\Channel;
35
use Zemit\Models\Field;
36
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...
37
use Zemit\Models\User;
38
use Zemit\Models\UserType;
39
use Zemit\Models\UserGroup;
40
use Zemit\Models\UserRole;
41
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...
42
use Zemit\Models\Role;
43
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...
44
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...
45
use Zemit\Models\Group;
46
use Zemit\Models\GroupRole;
47
use Zemit\Models\GroupType;
48
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...
49
use Zemit\Models\Type;
50
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...
51
52
/**
53
 * Allow to get mapped classes without using magic methods
54
 */
55
trait ModelsMap
56
{
57
    /**
58
     * Store an array of mapped models
59
     * @var array
60
     */
61
    public array $modelsMap;
62
    
63
    /**
64
     * @return DiInterface
65
     */
66
    abstract function getDI(): DiInterface;
0 ignored issues
show
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getDI.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

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