Test Failed
Pull Request — master (#160)
by Maximo
07:00
created

Apps::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 21
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 30
ccs 0
cts 26
cp 0
crap 2
rs 9.584
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 $ecosystem_auth;
57
58
    /**
59
     * @var integer
60
     */
61
    public $payments_active;
62
63
    /**
64
     *
65
     * @var string
66
     */
67
    public $created_at;
68
69
    /**
70
     *
71
     * @var string
72
     */
73
    public $updated_at;
74
75
    /**
76
     *
77
     * @var integer
78
     */
79
    public $is_deleted;
80
81
    /**
82
     * Ecosystem default app.
83
     * @var string
84
     */
85
    const CANVAS_DEFAULT_APP_ID = 1;
86
    const CANVAS_DEFAULT_APP_NAME = 'Default';
87
88
    /**
89
     * Users Associated Trait.
90
     */
91
    use UsersAssociatedTrait;
92
93
    /**
94
     * Model Settings Trait.
95
     */
96
    use HashTableTrait;
97
98
    /**
99
     * Initialize method for model.
100
     */
101
    public function initialize()
102
    {
103
        $this->setSource('apps');
104
105
        $this->hasOne(
106
            'default_apps_plan_id',
107
            'Canvas\Models\AppsPlans',
108
            'id',
109
            ['alias' => 'plan']
110
        );
111
112
        $this->hasMany(
113
            'id',
114
            'Canvas\Models\AppsPlans',
115
            'apps_id',
116
            ['alias' => 'plans']
117
        );
118
119
        $this->hasMany(
120
            'id',
121
            'Canvas\Models\UserWebhooks',
122
            'apps_id',
123
            ['alias' => 'user-webhooks']
124
        );
125
126
        $this->hasMany(
127
            'id',
128
            'Canvas\Models\AppsSettings',
129
            'apps_id',
130
            ['alias' => 'settingsApp']
131
        );
132
    }
133
134
    /**
135
     * You can only get 2 variations or default in DB or the api app.
136
     *
137
     * @param string $name
138
     * @return Apps
139
     */
140
    public static function getACLApp(string $name): Apps
141
    {
142
        if (trim($name) == self::CANVAS_DEFAULT_APP_NAME) {
143
            $app = self::findFirst(1);
144
        } else {
145
            $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...
146
        }
147
148
        return $app;
149
    }
150
151
    /**
152
     * Is active?
153
     *
154
     * @return boolean
155
     */
156
    public function isActive(): bool
157
    {
158
        return (bool) $this->is_actived;
159
    }
160
161
    /**
162
     * Returns table name mapped in the model.
163
     *
164
     * @return string
165
     */
166
    public function getSource() : string
167
    {
168
        return 'apps';
169
    }
170
171
    /**
172
     * Those this app use ecosystem login or
173
     * the its own local login?
174
     *
175
     * @return boolean
176
     */
177
    public function ecosystemAuth(): bool
178
    {
179
        return (bool) $this->ecosystem_auth;
180
    }
181
182
    /**
183
     * Is this app subscription based?
184
     *
185
     * @return boolean
186
     */
187
    public function subscriptioBased(): bool
188
    {
189
        return (bool) $this->payments_active;
190
    }
191
}
192