UserWebhooks   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 148
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSource() 0 3 1
A validation() 0 14 1
A getById() 0 8 1
A initialize() 0 30 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
use Phalcon\Di;
7
use Phalcon\Validation\Validator\Url;
0 ignored issues
show
Bug introduced by
The type Phalcon\Validation\Validator\Url 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...
8
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...
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;
23
24
    /**
25
     *
26
     * @var integer
27
     */
28
    public $apps_id;
29
30
    /**
31
     *
32
     * @var integer
33
     */
34
    public $users_id;
35
36
    /**
37
     *
38
     * @var integer
39
     */
40
    public $companies_id;
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;
65
66
    /**
67
     *
68
     * @var string
69
     */
70
    public $created_at;
71
72
    /**
73
     *
74
     * @var string
75
     */
76
    public $updated_at;
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