Failed Conditions
Pull Request — master (#284)
by Maximo
04:23
created

SystemModules::getByModelName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
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 Canvas\Http\Exception\InternalServerErrorException;
8
9
class SystemModules extends AbstractModel
10
{
11
    /**
12
     *
13
     * @var integer
14
     */
15
    public $id;
16
17
    /**
18
     *
19
     * @var integer
20
     */
21
    public $name;
22
23
    /**
24
     *
25
     * @var integer
26
     */
27
    public $slug;
28
29
    /**
30
     *
31
     * @var string
32
     */
33
    public $model_name;
0 ignored issues
show
Coding Style introduced by
$model_name 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 integer
38
     */
39
    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...
40
41
    /**
42
     *
43
     * @var integer
44
     */
45
    public $parents_id;
0 ignored issues
show
Coding Style introduced by
$parents_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...
46
47
    /**
48
     *
49
     * @var integer
50
     */
51
    public $menu_order;
0 ignored issues
show
Coding Style introduced by
$menu_order 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
     *
55
     * @var integer
56
     */
57
    public $use_elastic;
0 ignored issues
show
Coding Style introduced by
$use_elastic 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...
58
59
    /**
60
     *
61
     * @var string
62
     */
63
    public $browse_fields;
0 ignored issues
show
Coding Style introduced by
$browse_fields 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...
64
65
    /**
66
     *
67
     * @var integer
68
     */
69
    public $show;
70
71
    /**
72
     *
73
     * @var string
74
     */
75
    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...
76
77
    /**
78
     *
79
     * @var string
80
     */
81
    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...
82
83
    /**
84
     *
85
     * @var integer
86
     */
87
    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...
88
89
    /**
90
     * Initialize method for model.
91
     */
92
    public function initialize()
93
    {
94
        $this->hasMany(
95
            'id',
96
            'Canvas\Models\EmailTemplatesVariables',
97
            'system_modules_id',
98
            ['alias' => 'templateVariable']
99
        );
100
101
        $this->hasMany(
102
            'id',
103
            'Canvas\Models\Webhooks',
104
            'system_modules_id',
105
            ['alias' => 'webhook']
106
        );
107
108
        $this->belongsTo(
109
            'companies_id',
110
            'Canvas\Models\Companies',
111
            'id',
112
            ['alias' => 'company']
113
        );
114
115
        $this->belongsTo(
116
            'apps_id',
117
            'Canvas\Models\Apps',
118
            'id',
119
            ['alias' => 'app']
120
        );
121
122
        $this->belongsTo(
123
            'company_branches_id',
124
            'Canvas\Models\CompanyBranches',
125
            'id',
126
            ['alias' => 'companyBranch']
127
        );
128
    }
129
130
    /**
131
     * Returns table name mapped in the model.
132
     *
133
     * @return string
134
     */
135
    public function getSource(): string
136
    {
137
        return 'system_modules';
138
    }
139
140
    /**
141
     * Get System Module by its model_name.
142
     * 
143
     * @deprecated v2
144
     * @param string $model_name
0 ignored issues
show
Bug introduced by
There is no parameter named $model_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
145
     * @return SystemModules
146
     */
147
    public static function getSystemModuleByModelName(string $modelName): SystemModules
148
    {
149
        $module = SystemModules::findFirst([
150
            'conditions' => 'model_name = ?0 and apps_id = ?1',
151
            'bind' => [$modelName, Di::getDefault()->getApp()->getId()]
152
        ]);
153
154
        if (!is_object($module)) {
155
            throw new InternalServerErrorException('No system module for ' . $modelName);
156
        }
157
158
        return $module;
159
    }
160
161
    /**
162
     * Get System Module by its model_name.
163
     * 
164
     * @param string $model_name
0 ignored issues
show
Bug introduced by
There is no parameter named $model_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
165
     * @return SystemModules
166
     */
167
    public static function getByModelName(string $modelName): SystemModules
168
    {
169
        return self::getSystemModuleByModelName($modelName);
0 ignored issues
show
Deprecated Code introduced by
The method Canvas\Models\SystemModu...stemModuleByModelName() has been deprecated with message: v2

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
170
    }
171
172
    /**
173
     * Get System Module by id.
174
     *
175
     * @param int $id
176
     * @return SystemModules
177
     */
178
    public static function getById($id): SystemModules
179
    {
180
        $module = SystemModules::findFirstOrFail([
181
            'conditions' => 'id = ?0 and apps_id = ?1',
182
            'bind' => [$id, Di::getDefault()->getApp()->getId()]
183
        ]);
184
185
        return $module;
186
    }
187
188
    /**
189
     * Get System Module by id.
190
     *
191
     * @param int $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
192
     * @return SystemModules
193
     */
194
    public static function getBySlug(string $slug): SystemModules
195
    {
196
        $module = SystemModules::findFirstOrFail([
197
            'conditions' => 'slug = ?0 and apps_id = ?1',
198
            'bind' => [$slug, Di::getDefault()->getApp()->getId()]
199
        ]);
200
201
        return $module;
202
    }
203
204
    /**
205
     * Given tell them if this system module is index in elastic.
206
     *
207
     * @return bool
208
     */
209
    public function useElastic(): bool
0 ignored issues
show
Coding Style introduced by
function useElastic() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
210
    {
211
        return (bool) $this->use_elastic;
212
    }
213
}
214