UserRoles   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 107
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 30 1
A validation() 0 14 1
A getSource() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
use Phalcon\Validation;
0 ignored issues
show
Bug introduced by
The type Phalcon\Validation 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...
7
use Phalcon\Validation\Validator\Uniqueness;
8
9
class UserRoles extends AbstractModel
10
{
11
    /**
12
     *
13
     * @var integer
14
     */
15
    public $users_id;
16
17
    /**
18
     *
19
     * @var integer
20
     */
21
    public $apps_id;
22
23
    /**
24
     *
25
     * @var integer
26
     */
27
    public $roles_id;
28
29
    /**
30
     *
31
     * @var integer
32
     */
33
    public $companies_id;
34
35
    /**
36
     *
37
     * @var string
38
     */
39
    public $created_at;
40
41
    /**
42
     *
43
     * @var string
44
     */
45
    public $updated_at;
46
47
    /**
48
     *
49
     * @var integer
50
     */
51
    public $is_deleted;
52
53
    /**
54
     * Initialize method for model.
55
     */
56
    public function initialize()
57
    {
58
        $this->setSource('user_roles');
59
60
        $this->belongsTo(
61
            'users_id',
62
            'Canvas\Models\Users',
63
            'id',
64
            ['alias' => 'user']
65
        );
66
67
        $this->belongsTo(
68
            'roles_id',
69
            'Canvas\Models\Roles',
70
            'id',
71
            ['alias' => 'roles']
72
        );
73
74
        $this->belongsTo(
75
            'apps_id',
76
            'Canvas\Models\Apps',
77
            'id',
78
            ['alias' => 'app']
79
        );
80
81
        $this->belongsTo(
82
            'companies_id',
83
            'Canvas\Models\Companies',
84
            'id',
85
            ['alias' => 'company']
86
        );
87
    }
88
89
    /**
90
     * Returns table name mapped in the model.
91
     *
92
     * @return string
93
     */
94
    public function getSource(): string
95
    {
96
        return 'user_roles';
97
    }
98
99
    /**
100
    * Validations and business logic.
101
    */
102
    public function validation()
103
    {
104
        $validator = new Validation();
105
106
        $validator->add(
107
            ['users_id', 'apps_id', 'companies_id'],
108
            new Uniqueness(
109
                [
110
                    'message' => 'Can\'t have 2 roles for the same company on the same app - ' . $this->company->name
111
                ]
112
            )
113
        );
114
115
        return $this->validate($validator);
116
    }
117
}
118