Test Failed
Push — master ( 7bbbf4...34ff55 )
by Julien
04:57
created

ModelsMap::setClassMap()   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 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 1
    public function getConfig(): Config
70
    {
71 1
        return $this->getDI()->get('config');
72
    }
73
    
74
    /**
75
     * Get an array of mapped models
76
     */
77 1
    public function getModelsMap(): array
78
    {
79 1
        if (!isset($this->modelsMap)) {
80 1
            $this->setModelsMap();
81
        }
82 1
        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
    }
84
    
85
    /**
86
     * Set the models mapping or retrieve the mapped models from the config
87
     */
88 1
    public function setModelsMap(?array $modelsMap = null): void
89
    {
90 1
        $this->modelsMap = $modelsMap ?? $this->getConfig()->pathToArray('models') ?? [];
91
    }
92
    
93
    /**
94
     * Map a new class
95
     */
96 1
    public function setClassMap(string $map, ?string $class): void
97
    {
98 1
        $this->modelsMap[$map] = $class;
99
    }
100
    
101
    /**
102
     * Remove an existing class
103
     */
104 1
    public function removeClassMap(string $map): void
105
    {
106 1
        unset($this->modelsMap[$map]);
107
    }
108
    
109
    /**
110
     * Return the class mapping
111
     */
112 1
    public function getClassMap(string $class): string
113
    {
114 1
        return $this->getModelsMap()[$class] ?? $class;
115
    }
116
    
117
    /**
118
     * Return an instance of the class
119
     */
120
    public function getObjectMap(string $class): ModelInterface
121
    {
122
        $class = $this->getClassMap($class);
123
        return new $class();
124
    }
125
    
126
    /**
127
     * Return the mapped class name of \Zemit\Models\Backup::class
128
     */
129 1
    public function getBackupClass(): string
130
    {
131 1
        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 1
    public function getAuditDetailClass(): string
146
    {
147 1
        return $this->getClassMap(AuditDetail::class);
148
    }
149
    
150
    /**
151
     * Return the mapped class name of \Zemit\Models\Log::class
152
     */
153 1
    public function getLogClass(): string
154
    {
155 1
        return $this->getClassMap(Log::class);
156
    }
157
    
158
    /**
159
     * Return the mapped class name of \Zemit\Models\Email::class
160
     */
161 1
    public function getEmailClass(): string
162
    {
163 1
        return $this->getClassMap(Email::class);
164
    }
165
    
166
    /**
167
     * Return the mapped class name of \Zemit\Models\Job::class
168
     */
169 1
    public function getJobClass(): string
170
    {
171 1
        return $this->getClassMap(Job::class);
172
    }
173
    
174
    /**
175
     * Return the mapped class name of \Zemit\Models\File::class
176
     */
177 1
    public function getFileClass(): string
178
    {
179 1
        return $this->getClassMap(File::class);
180
    }
181
    
182
    /**
183
     * Return the mapped class name of \Zemit\Models\Session::class
184
     */
185 1
    public function getSessionClass(): string
186
    {
187 1
        return $this->getClassMap(Session::class);
188
    }
189
    
190
    /**
191
     * Return the mapped class name of \Zemit\Models\Flag::class
192
     */
193 1
    public function getFlagClass(): string
194
    {
195 1
        return $this->getClassMap(Flag::class);
196
    }
197
    
198
    /**
199
     * Return the mapped class name of \Zemit\Models\Setting::class
200
     */
201 1
    public function getSettingClass(): string
202
    {
203 1
        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 1
    public function getTranslateClass(): string
218
    {
219 1
        return $this->getClassMap(Translate::class);
220
    }
221
    
222
    /**
223
     * Return the mapped class name of \Zemit\Models\TranslateField::class
224
     */
225 1
    public function getTranslateFieldClass(): string
226
    {
227 1
        return $this->getClassMap(TranslateField::class);
228
    }
229
    
230
    /**
231
     * Return the mapped class name of \Zemit\Models\TranslateTable::class
232
     */
233 1
    public function getTranslateTableClass(): string
234
    {
235 1
        return $this->getClassMap(TranslateTable::class);
236
    }
237
    
238
    /**
239
     * Return the mapped class name of \Zemit\Models\Site::class
240
     */
241 1
    public function getSiteClass(): string
242
    {
243 1
        return $this->getClassMap(Site::class);
244
    }
245
    
246
    /**
247
     * Return the mapped class name of \Zemit\Models\SiteLang::class
248
     */
249 1
    public function getSiteLangClass(): string
250
    {
251 1
        return $this->getClassMap(SiteLang::class);
252
    }
253
    
254
    /**
255
     * Return the mapped class name of \Zemit\Models\Page::class
256
     */
257 1
    public function getPageClass(): string
258
    {
259 1
        return $this->getClassMap(Page::class);
260
    }
261
    
262
    /**
263
     * Return the mapped class name of \Zemit\Models\Post::class
264
     */
265 1
    public function getPostClass(): string
266
    {
267 1
        return $this->getClassMap(Post::class);
268
    }
269
    
270
    /**
271
     * Return the mapped class name of \Zemit\Models\Template::class
272
     */
273 1
    public function getTemplateClass(): string
274
    {
275 1
        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 1
    public function getFieldClass(): string
290
    {
291 1
        return $this->getClassMap(Field::class);
292
    }
293
    
294
    /**
295
     * Return the mapped class name of \Zemit\Models\Profile::class
296
     */
297 1
    public function getProfileClass(): string
298
    {
299 1
        return $this->getClassMap(Profile::class);
300
    }
301
    
302
    /**
303
     * Return the mapped class name of \Zemit\Models\User::class
304
     */
305 1
    public function getUserClass(): string
306
    {
307 1
        return $this->getClassMap(User::class);
308
    }
309
    
310
    /**
311
     * Return the mapped class name of \Zemit\Models\UserType::class
312
     */
313 1
    public function getUserTypeClass(): string
314
    {
315 1
        return $this->getClassMap(UserType::class);
316
    }
317
    
318
    /**
319
     * Return the mapped class name of \Zemit\Models\UserGroup::class
320
     */
321 1
    public function getUserGroupClass(): string
322
    {
323 1
        return $this->getClassMap(UserGroup::class);
324
    }
325
    
326
    /**
327
     * Return the mapped class name of \Zemit\Models\UserRole::class
328
     */
329 1
    public function getUserRoleClass(): string
330
    {
331 1
        return $this->getClassMap(UserRole::class);
332
    }
333
    
334
    /**
335
     * Return the mapped class name of \Zemit\Models\UserFeature::class
336
     */
337 1
    public function getUserFeatureClass(): string
338
    {
339 1
        return $this->getClassMap(UserFeature::class);
340
    }
341
    
342
    /**
343
     * Return the mapped class name of \Zemit\Models\Role::class
344
     */
345 1
    public function getRoleClass(): string
346
    {
347 1
        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 1
    public function getRoleFeatureClass(): string
362
    {
363 1
        return $this->getClassMap(RoleFeature::class);
364
    }
365
    
366
    /**
367
     * Return the mapped class name of \Zemit\Models\Group::class
368
     */
369 1
    public function getGroupClass(): string
370
    {
371 1
        return $this->getClassMap(Group::class);
372
    }
373
    
374
    /**
375
     * Return the mapped class name of \Zemit\Models\GroupRole::class
376
     */
377 1
    public function getGroupRoleClass(): string
378
    {
379 1
        return $this->getClassMap(GroupRole::class);
380
    }
381
    
382
    /**
383
     * Return the mapped class name of \Zemit\Models\GroupType::class
384
     */
385 1
    public function getGroupTypeClass(): string
386
    {
387 1
        return $this->getClassMap(GroupType::class);
388
    }
389
    
390
    /**
391
     * Return the mapped class name of \Zemit\Models\GroupFeature::class
392
     */
393 1
    public function getGroupFeatureClass(): string
394
    {
395 1
        return $this->getClassMap(GroupFeature::class);
396
    }
397
    
398
    /**
399
     * Return the mapped class name of \Zemit\Models\Type::class
400
     */
401 1
    public function getTypeClass(): string
402
    {
403 1
        return $this->getClassMap(Type::class);
404
    }
405
    
406
    /**
407
     * Return the mapped class name of \Zemit\Models\Feature::class
408
     */
409 1
    public function getFeatureClass(): string
410
    {
411 1
        return $this->getClassMap(Feature::class);
412
    }
413
}
414