Completed
Push — master ( 0edfe9...83485f )
by Dmitry
08:42
created

Resource   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 7
c 5
b 1
f 2
lcom 0
cbo 4
dl 0
loc 54
ccs 0
cts 36
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 13 1
A getTariff() 0 4 1
A getPart() 0 8 2
A attributeLabels() 0 5 1
A isTypeCorrect() 0 4 1
A getAvailableTypes() 0 4 1
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
use hipanel\modules\stock\models\Part;
15
use Yii;
16
use yii\base\InvalidConfigException;
17
18
class Resource extends \hipanel\base\Model
19
{
20
    use \hipanel\base\ModelTrait;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function rules()
26
    {
27
        return [
28
            [['id', 'tariff_id', 'object_id', 'type_id', 'unit_id', 'currency_id', 'hardlim'], 'integer'],
29
            [['type', 'ftype', 'unit', 'unit_factor', 'currency'], 'safe'],
30
            [['price', 'fee', 'quantity', 'discount'], 'number'],
31
32
            [['object_id', 'type_id'], 'integer', 'on' => ['create', 'update']],
33
            [['type'], 'safe', 'on' => ['create', 'update']],
34
            [['price'], 'number', 'on' => ['create', 'update']],
35
            'create-required' => [['object_id', 'price'], 'required', 'on' => ['create', 'update']],
36
        ];
37
    }
38
39
    public function getTariff()
40
    {
41
        return $this->hasOne(Tariff::class, ['tariff_id' => 'id']);
42
    }
43
44
    public function getPart()
45
    {
46
        if (!Yii::getAlias('@part', false)) {
47
            throw new InvalidConfigException('Stock module is a must to retrieve resource parts');
48
        }
49
50
        return $this->hasOne(Part::class, ['object_id' => 'id']);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function attributeLabels()
57
    {
58
        return $this->mergeAttributeLabels([
59
        ]);
60
    }
61
62
    public function isTypeCorrect()
63
    {
64
        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...
65
    }
66
67
    public function getAvailableTypes()
68
    {
69
        return [];
70
    }
71
}
72