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

Subscription::getActiveForThisApp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 2
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 6
    public function initialize()
19
    {
20 6
        $this->belongsTo('user_id', 'Gewaer\Models\Users', 'id', ['alias' => 'user']);
21
22 6
        $this->belongsTo(
23 6
            'company_id',
24 6
            'Gewaer\Models\Companies',
25 6
            'id',
26 6
            ['alias' => 'company']
27
        );
28
29 6
        $this->belongsTo(
30 6
            'apps_id',
31 6
            'Gewaer\Models\Apps',
32 6
            'id',
33 6
            ['alias' => 'app']
34
        );
35
36 6
        $this->belongsTo(
37 6
            'apps_plans_id',
38 6
            'Gewaer\Models\AppsPlans',
39 6
            'id',
40 6
            ['alias' => 'appPlan']
41
        );
42 6
    }
43
44
    /**
45
     * Get the active subscription for this company app
46
     *
47
     * @return void
48
     */
49 4
    public static function getActiveForThisApp() : Subscription
50
    {
51 4
        $subscription = self::findFirst([
52 4
            'conditions' => 'company_id = ?0 and apps_id = ?1 and is_deleted  = 0',
53 4
            'bind' => [Di::getDefault()->getUserData()->default_company, Di::getDefault()->getApp()->getId()]
54
        ]);
55
56 4
        if (!is_object($subscription)) {
57 2
            throw new ServerErrorHttpException(_('No active subscription for this app ' . Di::getDefault()->getApp()->getId() . ' at the company ' . Di::getDefault()->getUserData()->default_company));
58
        }
59
60 2
        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