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

Subscription   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 52
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 23 1
A getActiveForThisApp() 0 12 2
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 2
    public function initialize()
19
    {
20 2
        $this->belongsTo('user_id', 'Gewaer\Models\Users', 'id', ['alias' => 'user']);
21
22 2
        $this->belongsTo(
23 2
            'company_id',
24 2
            'Gewaer\Models\Companies',
25 2
            'id',
26 2
            ['alias' => 'company']
27
        );
28
29 2
        $this->belongsTo(
30 2
            'apps_id',
31 2
            'Gewaer\Models\Apps',
32 2
            'id',
33 2
            ['alias' => 'app']
34
        );
35
36 2
        $this->belongsTo(
37 2
            'apps_plans_id',
38 2
            'Gewaer\Models\AppsPlans',
39 2
            'id',
40 2
            ['alias' => 'appPlan']
41
        );
42 2
    }
43
44
    /**
45
     * Get the active subscription for this company app
46
     *
47
     * @return void
48
     */
49 1
    public static function getActiveForThisApp() : Subscription
50
    {
51 1
        $subscription = self::findFirst([
52 1
            'conditions' => 'company_id = ?0 and apps_id = ?1 and is_deleted  = 0',
53 1
            'bind' => [Di::getDefault()->getUserData()->default_company, Di::getDefault()->getApp()->getId()]
54
        ]);
55
56 1
        if (!is_object($subscription)) {
57 1
            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