Test Failed
Pull Request — master (#135)
by Rafael
06:12
created

Apps::getACLApp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 3
cts 5
cp 0.6
crap 2.2559
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Models;
5
6
use Canvas\Traits\UsersAssociatedTrait;
7
use Baka\Database\Contracts\HashTableTrait;
8
9
class Apps extends \Baka\Database\Apps
10
{
11
    /**
12
     *
13
     * @var integer
14
     */
15
    public $id;
16
17
    /**
18
     *
19
     * @var string
20
     */
21
    public $key;
22
23
    /**
24
     *
25
     * @var string
26
     */
27
    public $name;
28
29
    /**
30
     *
31
     * @var string
32
     */
33
    public $description;
34
35
    /**
36
     *
37
     * @var string
38
     */
39
    public $url;
40
41
    /**
42
     *
43
     * @var integer
44
     */
45
    public $default_apps_plan_id;
46
47
    /**
48
     *
49
     * @var integer
50
     */
51
    public $is_actived;
52
53
    /**
54
     * @var integer
55
     */
56
    public $payments_active;
57
58
    /**
59
     *
60
     * @var string
61
     */
62
    public $created_at;
63
64
    /**
65
     *
66
     * @var string
67
     */
68
    public $updated_at;
69
70
    /**
71
     *
72
     * @var integer
73
     */
74
    public $is_deleted;
75
76
    /**
77
     * Ecosystem default app.
78
     * @var string
79
     */
80
    const CANVAS_DEFAULT_APP_ID = 1;
81
    const CANVAS_DEFAULT_APP_NAME = 'Default';
82
83
    /**
84
     * Users Associated Trait.
85
     */
86
    use UsersAssociatedTrait;
87
88
    /**
89
     * Model Settings Trait.
90
     */
91
    use HashTableTrait;
92
93
    /**
94
     * Initialize method for model.
95
     */
96 1
    public function initialize()
97
    {
98 1
        $this->setSource('apps');
99
100 1
        $this->hasOne(
101 1
            'default_apps_plan_id',
102 1
            'Canvas\Models\AppsPlans',
103 1
            'id',
104 1
            ['alias' => 'plan']
105
        );
106
107 1
        $this->hasMany(
108 1
            'id',
109 1
            'Canvas\Models\AppsPlans',
110 1
            'apps_id',
111 1
            ['alias' => 'plans']
112
        );
113
114 1
        $this->hasMany(
115 1
            'id',
116 1
            'Canvas\Models\UserWebhooks',
117 1
            'apps_id',
118 1
            ['alias' => 'user-webhooks']
119
        );
120
121 1
        $this->hasMany(
122 1
            'id',
123 1
            'Canvas\Models\AppsSettings',
124 1
            'apps_id',
125 1
            ['alias' => 'settingsApp']
126
        );
127 1
    }
128
129
    /**
130
     * You can only get 2 variations or default in DB or the api app.
131
     *
132
     * @param string $name
133
     * @return Apps
134
     */
135 2
    public static function getACLApp(string $name): Apps
136
    {
137 2
        if (trim($name) == self::CANVAS_DEFAULT_APP_NAME) {
138 2
            $app = self::findFirst(1);
139
        } else {
140
            $app = self::findFirstByKey(\Phalcon\DI::getDefault()->getConfig()->app->id);
0 ignored issues
show
Bug introduced by
The type Phalcon\DI 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...
141
        }
142
143
        return $app;
144
    }
145
146
    /**
147
     * Is active?
148
     *
149
     * @return boolean
150
     */
151
    public function isActive(): bool
152
    {
153
        return (bool) $this->is_actived;
154
    }
155
156
    /**
157
     * Returns table name mapped in the model.
158
     *
159
     * @return string
160
     */
161 2
    public function getSource() : string
162
    {
163 2
        return 'apps';
164
    }
165
}
166