Test Failed
Push — master ( 51765d...a30637 )
by Julien
03:53
created

ModelsMap::getUserRoleClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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;
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
     * Config from DI
59
     * @var Config
60
     */
61
    public Config $_config;
62
    
63
    /**
64
     * Store an array of mapped models
65
     * @var array
66
     */
67
    public array $modelsMap;
68
    
69
    /**
70
     * Retrieve the config from DI
71
     * @return Config
72
     */
73
    public function getConfig(): Config
74
    {
75
        if (!isset($this->_config)) {
76
            $this->_config =
77
                $this->config ??
0 ignored issues
show
Bug introduced by
The property config does not exist on Zemit\Support\ModelsMap. Did you mean _config?
Loading history...
78
                $this->getDI()->get('config') ??
0 ignored issues
show
Bug introduced by
It seems like getDI() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

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