Completed
Push — master ( 0e490c...4b4ef3 )
by Dmitry
11:06
created

CertificateTariffManager::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.8666
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\logic;
12
13
use hipanel\models\Ref;
14
use hipanel\modules\finance\forms\CertificateTariffForm;
15
use hipanel\modules\finance\models\Tariff;
16
use hiqdev\hiart\ConnectionInterface;
17
use hiqdev\hiart\ResponseErrorException;
18
use Yii;
19
use yii\base\InvalidConfigException;
20
use yii\web\NotFoundHttpException;
21
use yii\web\UnprocessableEntityHttpException;
22
23
/**
24
 * Class CertificateTariffManager
25
 *
26
 * @author Dmytro Naumenko <[email protected]>
27
 */
28
class CertificateTariffManager extends AbstractTariffManager
29
{
30
    /**
31
     * @var CertificateTariffForm
32
     */
33
    public $form;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected $type = Tariff::TYPE_CERT;
39
40
    /**
41
     * @var ConnectionInterface
42
     */
43
    private $connection;
44
45
    public function __construct(ConnectionInterface $connection, $config = [])
46
    {
47
        $this->connection = $connection;
48
49
        parent::__construct($config);
50
    }
51
52
    public function init()
53
    {
54
        if (!Yii::getAlias('@certificate', true)) {
55
            throw new InvalidConfigException('Certificate module is missing');
56
        }
57
58
        parent::init();
59
    }
60
61
    protected function determineParentTariff()
62
    {
63
        $id = parent::determineParentTariff();
64
65
        if ($id === null) {
66
            $tariff = reset(Tariff::find()
0 ignored issues
show
Bug introduced by
\hipanel\modules\finance...=> $this->type))->all() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
67
                ->action('get-available-info')
68
                ->andFilterWhere(['type' => $this->type])
69
                ->all());
70
71
            if ($tariff instanceof Tariff) {
72
                $id = $tariff->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<hipanel\modules\finance\models\Tariff>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
73
            }
74
        }
75
76
        return $id;
77
    }
78
79
    protected function getFormOptions()
80
    {
81
        return array_merge([
82
            'class' => CertificateTariffForm::class,
83
            'certificateTypes' => Ref::getList('type,certificate', 'hipanel:certificate', [
84
                'select' => 'id_label',
85
                'mapOptions' => ['from' => 'id'],
86
            ]),
87
        ], parent::getFormOptions());
88
    }
89
}
90