Failed Conditions
Pull Request — master (#298)
by Maximo
03:20
created

UserRoles::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 32
ccs 0
cts 25
cp 0
crap 2
rs 9.408
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
use Phalcon\Validation;
7
use Phalcon\Validation\Validator\Uniqueness;
8
9
class UserRoles extends AbstractModel
10
{
11
    /**
12
     *
13
     * @var integer
14
     */
15
    public $users_id;
0 ignored issues
show
Coding Style introduced by
$users_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
16
17
    /**
18
     *
19
     * @var integer
20
     */
21
    public $apps_id;
0 ignored issues
show
Coding Style introduced by
$apps_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
22
23
    /**
24
     *
25
     * @var integer
26
     */
27
    public $roles_id;
0 ignored issues
show
Coding Style introduced by
$roles_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
28
29
    /**
30
     *
31
     * @var integer
32
     */
33
    public $companies_id;
0 ignored issues
show
Coding Style introduced by
$companies_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
34
35
    /**
36
     *
37
     * @var string
38
     */
39
    public $created_at;
0 ignored issues
show
Coding Style introduced by
$created_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
40
41
    /**
42
     *
43
     * @var string
44
     */
45
    public $updated_at;
0 ignored issues
show
Coding Style introduced by
$updated_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
46
47
    /**
48
     *
49
     * @var integer
50
     */
51
    public $is_deleted;
0 ignored issues
show
Coding Style introduced by
$is_deleted does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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