Test Failed
Pull Request — master (#12)
by Maximo
03:04
created

Apps::getACLApp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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 $created_at;
31
32
    /**
33
     *
34
     * @var string
35
     */
36
    public $updated_at;
37
38
    /**
39
     *
40
     * @var integer
41
     */
42
    public $is_deleted;
43
44
    /**
45
     * Ecosystem default app
46
     * @var string
47
     */
48
    const GEWAER_DEFAULT_APP_NAME = 'Default';
49
50
    /**
51
     * Initialize method for model.
52
     */
53 13
    public function initialize()
54
    {
55 13
        parent::initialize();
56
57 13
        $this->setSource('apps');
58 13
    }
59
60
    /**
61
     * You can only get 2 variations or default in DB or the api app
62
     *
63
     * @param string $name
64
     * @return Apps
65
     */
66 11
    public static function getACLApp(string $name): Apps
67
    {
68 11
        if (trim($name) == self::GEWAER_DEFAULT_APP_NAME) {
69 10
            $app = self::findFirst(0);
70
        } else {
71 1
            $app = self::findFirst(\Phalcon\DI::getDefault()->getConfig()->app->id);
72
        }
73
74 11
        return $app;
75
    }
76
77
    /**
78
     * Returns table name mapped in the model.
79
     *
80
     * @return string
81
     */
82 11
    public function getSource() : string
83
    {
84 11
        return 'apps';
85
    }
86
}
87