Completed
Push — master ( e3a066...ae53ec )
by Dmitry
09:38
created

Resource::getAvailableTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Finance module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-finance
7
 * @package   hipanel-module-finance
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\finance\models;
13
14
class Resource extends \hipanel\base\Model
15
{
16
    use \hipanel\base\ModelTrait;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function rules()
22
    {
23
        return [
24
            [['id', 'tariff_id', 'object_id', 'type_id', 'unit_id', 'currency_id', 'hardlim'], 'integer'],
25
            [['type', 'ftype', 'unit', 'unit_factor', 'currency'], 'safe'],
26
            [['price', 'fee', 'quantity', 'discount'], 'number'],
27
28
            [['object_id', 'type_id'], 'integer', 'on' => ['create', 'update']],
29
            [['type'], 'safe', 'on' => ['create', 'update']],
30
            [['price'], 'number', 'on' => ['create', 'update']],
31
            'create-required' => [['object_id', 'price'], 'required', 'on' => ['create', 'update']],
32
        ];
33
    }
34
35
    public function getTariff()
36
    {
37
        return $this->hasOne(Tariff::class, ['tariff_id' => 'id']);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function attributeLabels()
44
    {
45
        return $this->mergeAttributeLabels([
46
        ]);
47
    }
48
49
    public function isTypeCorrect()
50
    {
51
        return isset($this->getAvailableTypes()[$this->type]);
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<hipanel\modules\finance\models\Resource>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
52
    }
53
54
    public function getAvailableTypes()
55
    {
56
        return [];
57
    }
58
}
59