Test Failed
Pull Request — master (#21)
by Maximo
04:17
created

Subscription::getActiveForThisApp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Gewaer\Models;
4
5
use Phalcon\Cashier\Subscription as PhalconSubscription;
6
use Gewaer\Exception\ServerErrorHttpException;
7
use Phalcon\Di;
8
9
class Subscription extends PhalconSubscription
10
{
11
    public $apps_plans_id = 0;
12
13
    /**
14
     * Initialize
15
     *
16
     * @return void
17
     */
18
    public function initialize()
19
    {
20
        $this->belongsTo('user_id', 'Gewaer\Models\Users', 'id', ['alias' => 'user']);
21
22
        $this->belongsTo(
23
            'company_id',
24
            'Gewaer\Models\Companies',
25
            'id',
26
            ['alias' => 'company']
27
        );
28
29
        $this->belongsTo(
30
            'apps_id',
31
            'Gewaer\Models\Apps',
32
            'id',
33
            ['alias' => 'app']
34
        );
35
36
        $this->belongsTo(
37
            'apps_plans_id',
38
            'Gewaer\Models\AppsPlans',
39
            'id',
40
            ['alias' => 'appPlan']
41
        );
42
    }
43
44
    /**
45
     * Get the active subscription for this company app
46
     *
47
     * @return void
48
     */
49
    public static function getActiveForThisApp() : Subscription
50
    {
51
        $subscription = self::findFirst([
52
            'conditions' => 'company_id = ?0 and apps_id = ?1 and is_deleted  = 0',
53
            'bind' => [Di::getDefault()->getUserData()->default_company, Di::getDefault()->getApp()->getId()]
54
        ]);
55
56
        if (!is_object($subscription)) {
57
            throw new ServerErrorHttpException(_('No active subscription for this app ' . Di::getDefault()->getApp()->getId() . ' at the company ' . Di::getDefault()->getUserData()->default_company));
58
        }
59
60
        return $subscription;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $subscription returns the type Phalcon\Mvc\Model which includes types incompatible with the type-hinted return Gewaer\Models\Subscription.
Loading history...
61
    }
62
}
63