Completed
Push — master ( ae53ec...716429 )
by Dmitry
15:10
created

AbstractTariffManager::findBaseTariffs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 6
1
<?php
2
3
namespace hipanel\modules\finance\logic;
4
5
use hipanel\modules\finance\forms\AbstractTariffForm;
6
use hipanel\modules\finance\models\Tariff;
7
use yii\base\InvalidConfigException;
8
use yii\base\Object;
9
use yii\helpers\ArrayHelper;
10
use yii\web\ForbiddenHttpException;
11
12
abstract class AbstractTariffManager extends Object
13
{
14
    /**
15
     * @var Tariff[] array of all available base tariffs
16
     */
17
    protected $baseTariffs;
18
19
    /**
20
     * @var AbstractTariffForm
21
     */
22
    public $form;
23
24
    /**
25
     * @var string
26
     */
27
    public $scenario;
28
29
    /**
30
     * @var Tariff The actual tariff
31
     */
32
    protected $tariff;
33
34
    /**
35
     * @var string The type used to find base tariff
36
     */
37
    protected $type;
38
    
39
    public function init()
40
    {
41
        $this->findBaseTariffs();
42
        $this->buildForm();
43
    }
44
45
    /**
46
     * Fills [[form]] property with a proper [[AbstractTariffForm]] object
47
     */
48
    protected function buildForm()
49
    {
50
        throw new InvalidConfigException('Method "createForm" must be implemented');
51
    }
52
53
    protected function findBaseTariffs()
54
    {
55
        $availableTariffs = Tariff::perform('GetAvailableInfo', ['type' => $this->type], true);
56
57
        if (empty($availableTariffs)) {
58
            throw new ForbiddenHttpException('No available tariffs found');
59
        }
60
61
        $query = Tariff::find()->joinWith('resources')->prepare();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $query is correct as \hipanel\modules\finance...'resources')->prepare() (which targets hiqdev\hiart\ActiveQuery::prepare()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
62
        $this->baseTariffs = $query->populate($availableTariffs);
0 ignored issues
show
Bug introduced by
The method populate cannot be called on $query (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
63
    }
64
65
    public function getType()
66
    {
67
        return $this->type;
68
    }
69
70
    /**
71
     * @param Tariff $tariff
72
     */
73
    public function setTariff($tariff)
74
    {
75
        $this->tariff = $tariff;
76
    }
77
}
78