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

SystemModules::getBySlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

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 9
ccs 0
cts 0
cp 0
crap 2
rs 9.9666
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
use Phalcon\Mvc\ModelInterface;
9
10
class SystemModules extends AbstractModel
11
{
12
    /**
13
     *
14
     * @var integer
15
     */
16
    public $id;
17
18
    /**
19
     *
20
     * @var integer
21
     */
22
    public $name;
23
24
    /**
25
     *
26
     * @var integer
27
     */
28
    public $slug;
29
30
    /**
31
     *
32
     * @var string
33
     */
34
    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...
35
36
    /**
37
     *
38
     * @var integer
39
     */
40
    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...
41
42
    /**
43
     *
44
     * @var integer
45
     */
46
    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...
47
48
    /**
49
     *
50
     * @var integer
51
     */
52
    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...
53
54
    /**
55
     *
56
     * @var integer
57
     */
58
    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...
59
60
    /**
61
     *
62
     * @var string
63
     */
64
    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...
65
66
    /**
67
     *
68
     * @var integer
69
     */
70
    public $show;
71
72
    /**
73
     *
74
     * @var string
75
     */
76
    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...
77
78
    /**
79
     *
80
     * @var string
81
     */
82
    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...
83
84
    /**
85
     *
86
     * @var integer
87
     */
88
    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...
89
90
    /**
91
     * Initialize method for model.
92
     */
93
    public function initialize()
94
    {
95
        $this->hasMany(
96
            'id',
97
            'Canvas\Models\EmailTemplatesVariables',
98
            'system_modules_id',
99
            ['alias' => 'templateVariable']
100
        );
101
102
        $this->hasMany(
103
            'id',
104
            'Canvas\Models\Webhooks',
105
            'system_modules_id',
106
            ['alias' => 'webhook']
107
        );
108
109
        $this->belongsTo(
110
            'companies_id',
111
            'Canvas\Models\Companies',
112
            'id',
113
            ['alias' => 'company']
114
        );
115
116
        $this->belongsTo(
117
            'apps_id',
118
            'Canvas\Models\Apps',
119
            'id',
120
            ['alias' => 'app']
121
        );
122
123
        $this->belongsTo(
124
            'company_branches_id',
125
            'Canvas\Models\CompanyBranches',
126
            'id',
127
            ['alias' => 'companyBranch']
128
        );
129
    }
130
131
    /**
132
     * Returns table name mapped in the model.
133
     *
134
     * @return string
135
     */
136
    public function getSource(): string
137
    {
138
        return 'system_modules';
139
    }
140
141
    /**
142
     * Get System Module by its model_name.
143
     *
144
     * @deprecated v2
145
     * @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...
146
     * @return ModelInterface
147
     */
148
    public static function getSystemModuleByModelName(string $modelName): ModelInterface
149
    {
150
        $module = SystemModules::findFirst([
151
            'conditions' => 'model_name = ?0 and apps_id = ?1',
152
            'bind' => [$modelName, Di::getDefault()->getApp()->getId()]
153
        ]);
154
155
        if (!is_object($module)) {
156
            throw new InternalServerErrorException('No system module for ' . $modelName);
157
        }
158
159
        return $module;
160
    }
161
162
    /**
163
     * Get System Module by its model_name.
164
     *
165
     * @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...
166
     * @return ModelInterface
167
     */
168
    public static function getByModelName(string $modelName): ModelInterface
169
    {
170
        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...
171
    }
172
173
    /**
174
     * Get System Module by Name.
175
     *
176
     * @param string $name
177
     * @return ModelInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SystemModules.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
178
     */
179
    public static function getByName(string $name): ModelInterface
180
    {
181
        return self::findFirstOrFail([
182
            'conditions' => 'name = ?0 and apps_id = ?1',
183
            'bind' => [
184
                $name,
185
                Di::getDefault()->getApp()->getId()
186
            ]
187
        ]);
188
    }
189
190
    /**
191
     * Get System Module by id.
192
     *
193
     * @param int $id
194
     * @return ModelInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SystemModules.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
195
     */
196
    public static function getById($id): ModelInterface
197
    {
198
        $module = SystemModules::findFirstOrFail([
199
            'conditions' => 'id = ?0 and apps_id = ?1',
200
            'bind' => [$id, Di::getDefault()->getApp()->getId()]
201
        ]);
202
203
        return $module;
204
    }
205
206
    /**
207
     * Get System Module by id.
208
     *
209
     * @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...
210
     * @return ModelInterface
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SystemModules.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
211
     */
212
    public static function getBySlug(string $slug): ModelInterface
213
    {
214
        $module = SystemModules::findFirstOrFail([
215
            'conditions' => 'slug = ?0 and apps_id = ?1',
216
            'bind' => [$slug, Di::getDefault()->getApp()->getId()]
217
        ]);
218
219
        return $module;
220
    }
221
222
    /**
223
     * Given tell them if this system module is index in elastic.
224
     *
225
     * @return bool
226
     */
227
    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...
228
    {
229
        return (bool) $this->use_elastic;
230
    }
231
}
232