Test Failed
Pull Request — master (#70)
by Rafael
05:22
created

UserCompanyApps::getCurrentApp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Gewaer\Models;
5
6
use Phalcon\Di;
7
8
class UserCompanyApps extends \Baka\Auth\Models\UserCompanyApps
9
{
10
    /**
11
     *
12
     * @var integer
13
     */
14
    public $companies_id;
15
16
    /**
17
     *
18
     * @var integer
19
     */
20
    public $apps_id;
21
22
    /**
23
     *
24
     * @var string
25
     */
26
    public $stripe_id;
27
28
    /**
29
     *
30
     * @var integer
31
     */
32
    public $subscriptions_id;
33
34
    /**
35
     *
36
     * @var string
37
     */
38
    public $created_at;
39
40
    /**
41
     *
42
     * @var string
43
     */
44
    public $updated_at;
45
46
    /**
47
     *
48
     * @var integer
49
     */
50
    public $is_deleted;
51
52
    /**
53
     * Initialize method for model.
54
     */
55
    public function initialize()
56
    {
57
        parent::initialize();
58
59
        $this->belongsTo(
60
            'companies_id',
61
            'Gewaer\Models\Companies',
62
            'id',
63
            ['alias' => 'company']
64
        );
65
66
        $this->belongsTo(
67
            'apps_id',
68
            'Gewaer\Models\Apps',
69
            'id',
70
            ['alias' => 'app']
71
        );
72
73
        $this->setSource('user_company_apps');
74
    }
75
76
    /**
77
     * Returns table name mapped in the model.
78
     *
79
     * @return string
80
     */
81
    public function getSource() : string
82
    {
83
        return 'user_company_apps';
84
    }
85
86
    /**
87
     * Get the current company app
88
     *
89
     * @return void
90
     */
91
    public static function getCurrentApp(): UserCompanyApps
92
    {
93
        return self::findFirst([
94
            'conditions' => 'companies_id = ?0 and apps_id = ?1',
95
            'bind' => [Di::getDefault()->getUserData()->currentCompanyId(), Di::getDefault()->getApp()->getId()]
96
        ]);
97
    }
98
}
99