Completed
Push — master ( 844c41...030ae6 )
by Dmitry
04:17
created

AbstractTariffManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 50
ccs 0
cts 15
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createForm() 0 4 1
A findBaseModel() 0 10 2
A getType() 0 4 1
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\web\ForbiddenHttpException;
9
10
abstract class AbstractTariffManager
11
{
12
    /**
13
     * @var Tariff
14
     */
15
    public $baseTariff;
16
17
    /**
18
     * @var AbstractTariffForm
19
     */
20
    public $form;
21
22
    /**
23
     * @var string The type used to find base tariff
24
     */
25
    protected $type;
26
27
    public function __construct($tariff = null)
28
    {
29
        $this->findBaseModel();
30
        $this->createForm($tariff);
31
    }
32
33
    /**
34
     * Fills [[form]] property with a proper
35
     *
36
     * @param Tariff $tariff
37
     * @throws InvalidConfigException
38
     */
39
    protected function createForm($tariff = null)
40
    {
41
        throw new InvalidConfigException("Method createForm must be implemented");
42
    }
43
44
    protected function findBaseModel()
45
    {
46
        $availableTariffs = Tariff::perform('GetAvailableInfo', ['type' => $this->type], true);
47
        if (empty($availableTariffs)) {
48
            throw new ForbiddenHttpException('No available domain tariffs found');
49
        }
50
51
        $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...
52
        $this->baseTariff = reset($query->populate($availableTariffs));
0 ignored issues
show
Bug introduced by
$query->populate($availableTariffs) cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
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...
53
    }
54
55
    public function getType()
56
    {
57
        return $this->type;
58
    }
59
}
60