Failed Conditions
Pull Request — master (#284)
by Maximo
02:56
created

UserWebhooks::validation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

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 15
ccs 0
cts 0
cp 0
crap 2
rs 9.7666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
use Phalcon\Di;
7
use Phalcon\Validation\Validator\Url;
8
use Phalcon\Validation;
9
10
class UserWebhooks extends AbstractModel
11
{
12
    /**
13
     *
14
     * @var integer
15
     */
16
    public $id;
17
18
    /**
19
     *
20
     * @var integer
21
     */
22
    public $webhooks_id;
0 ignored issues
show
Coding Style introduced by
$webhooks_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...
23
24
    /**
25
     *
26
     * @var integer
27
     */
28
    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...
29
30
    /**
31
     *
32
     * @var integer
33
     */
34
    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...
35
36
    /**
37
     *
38
     * @var integer
39
     */
40
    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...
41
42
    /**
43
     *
44
     * @var string
45
     */
46
    public $url;
47
48
    /**
49
     *
50
     * @var string
51
     */
52
    public $method;
53
54
    /**
55
     *
56
     * @var string
57
     */
58
    public $format;
59
60
    /**
61
     *
62
     * @var integer
63
     */
64
    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...
65
66
    /**
67
     *
68
     * @var string
69
     */
70
    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...
71
72
    /**
73
     *
74
     * @var string
75
     */
76
    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...
77
78
    /**
79
     * Initialize method for model.
80
     */
81
    public function initialize()
82
    {
83
        $this->setSource('user_webhooks');
84
85
        $this->belongsTo(
86
            'webhooks_id',
87
            'Canvas\Models\Webhooks',
88
            'id',
89
            ['alias' => 'webhook']
90
        );
91
92
        $this->belongsTo(
93
            'users_id',
94
            'Canvas\Models\Users',
95
            'id',
96
            ['alias' => 'user']
97
        );
98
99
        $this->belongsTo(
100
            'companies_id',
101
            'Canvas\Models\Companies',
102
            'id',
103
            ['alias' => 'company']
104
        );
105
106
        $this->belongsTo(
107
            'apps_id',
108
            'Canvas\Models\Apps',
109
            'id',
110
            ['alias' => 'app']
111
        );
112
    }
113
114
    /**
115
     * Returns table name mapped in the model.
116
     *
117
     * @return string
118
     */
119
    public function getSource(): string
120
    {
121
        return 'user_webhooks';
122
    }
123
124
    /**
125
     * Validate input data.
126
     *
127
     * @return void
128
     */
129
    public function validation()
130
    {
131
        $validator = new Validation();
132
133
        $validator->add(
134
            'url',
135
            new Url(
136
                [
137
                    'message' => 'This Url is not valid',
138
                ]
139
            )
140
        );
141
142
        return $this->validate($validator);
143
    }
144
145
    /**
146
    * Get element by Id.
147
    *
148
    * @return Webhooks
149
    */
150
    public static function getById($id): self
151
    {
152
        return self::findFirstOrFail([
153
            'conditions' => 'id = ?0 AND apps_id = ?1 AND companies_id = ?2 and is_deleted = 0',
154
            'bind' => [
155
                $id,
156
                Di::getDefault()->getApp()->getId(),
157
                Di::getDefault()->getUserData()->getDefaultCompany()->getId()
158
            ]
159
        ]);
160
    }
161
}
162