Failed Conditions
Pull Request — master (#55)
by Rafael
05:25
created

UsersAssociatedTrait::saveUsersAssociatedModels()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 13
ccs 10
cts 11
cp 0.9091
crap 2.003
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Traits;
6
7
/**
8
 * Trait ResponseTrait
9
 *
10
 * @package Gewaer\Traits
11
 *
12
 * @property Users $user
13
 * @property Config $config
14
 * @property Request $request
15
 * @property Auth $auth
16
 * @property \Phalcon\Di $di
17
 *
18
 */
19
trait UsersAssociatedTrait
20
{
21
    /**
22
     * create new related User Associated instance dynamicly
23
     * @param string $model
24
     * @return voic
0 ignored issues
show
Bug introduced by
The type Gewaer\Traits\voic 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...
25
     * @todo Find a better way to handle namespaces for models
26
     */
27 3
    public function saveUsersAssociatedModels(string $model): void
28
    {
29 3
        $class = '\Gewaer\Models\UsersAssociated' . ucfirst($model);
30 3
        $usersAssociatedModel = new $class();
31 3
        $usersAssociatedModel->users_id = $this->user->getId();
32 3
        $usersAssociatedModel->companies_id = $this->getId();
33 3
        $usersAssociatedModel->apps_id = $this->di->getApp()->getId();
34 3
        $usersAssociatedModel->identify_id = $this->user->getId();
35 3
        $usersAssociatedModel->user_active = 1;
36 3
        $usersAssociatedModel->user_role = 'admin';
37
38 3
        if (!$usersAssociatedModel->save()) {
39
            throw new Exception((string)current($usersAssociatedModel->getMessages()));
0 ignored issues
show
Bug introduced by
The type Gewaer\Traits\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
40
        }
41 3
    }
42
}
43