Passed
Pull Request — master (#35)
by Rafael
04:25
created

Apps   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 129
ccs 26
cts 28
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isActive() 0 3 1
A getACLApp() 0 9 2
A getSource() 0 3 1
A initialize() 0 25 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Gewaer\Models;
5
6
class Apps extends \Baka\Auth\Models\Apps
7
{
8
    /**
9
     *
10
     * @var integer
11
     */
12
    public $id;
13
14
    /**
15
     *
16
     * @var string
17
     */
18
    public $name;
19
20
    /**
21
     *
22
     * @var string
23
     */
24
    public $description;
25
26
    /**
27
     *
28
     * @var string
29
     */
30
    public $url;
31
32
    /**
33
     *
34
     * @var integer
35
     */
36
    public $default_apps_plan_id;
37
38
    /**
39
     *
40
     * @var integer
41
     */
42
    public $is_actived;
43
44
    /**
45
     *
46
     * @var string
47
     */
48
    public $created_at;
49
50
    /**
51
     *
52
     * @var string
53
     */
54
    public $updated_at;
55
56
    /**
57
     *
58
     * @var integer
59
     */
60
    public $is_deleted;
61
62
    /**
63
     * Ecosystem default app
64
     * @var string
65
     */
66
    const GEWAER_DEFAULT_APP_ID = 0;
67
    const GEWAER_DEFAULT_APP_NAME = 'Default';
68
69
    /**
70
     * Initialize method for model.
71
     */
72 66
    public function initialize()
73
    {
74 66
        parent::initialize();
75
76 66
        $this->setSource('apps');
77
78 66
        $this->hasOne(
79 66
            'default_apps_plan_id',
80 66
            'Gewaer\Models\AppsPlans',
81 66
            'id',
82 66
            ['alias' => 'plan']
83
        );
84
85 66
        $this->hasMany(
86 66
            'id',
87 66
            'Gewaer\Models\AppsPlans',
88 66
            'apps_id',
89 66
            ['alias' => 'plans']
90
        );
91
92 66
        $this->hasMany(
93 66
            'id',
94 66
            'Gewaer\Models\UserWebhooks',
95 66
            'apps_id',
96 66
            ['alias' => 'user-webhooks']
97
        );
98 66
    }
99
100
    /**
101
     * You can only get 2 variations or default in DB or the api app
102
     *
103
     * @param string $name
104
     * @return Apps
105
     */
106 11
    public static function getACLApp(string $name): Apps
107
    {
108 11
        if (trim($name) == self::GEWAER_DEFAULT_APP_NAME) {
109 10
            $app = self::findFirst(0);
110
        } else {
111 1
            $app = self::findFirst(\Phalcon\DI::getDefault()->getConfig()->app->id);
112
        }
113
114 11
        return $app;
115
    }
116
117
    /**
118
     * Is active?
119
     *
120
     * @return boolean
121
     */
122
    public function isActive(): bool
123
    {
124
        return (bool) $this->is_actived;
125
    }
126
127
    /**
128
     * Returns table name mapped in the model.
129
     *
130
     * @return string
131
     */
132 66
    public function getSource() : string
133
    {
134 66
        return 'apps';
135
    }
136
}
137