Completed
Push — master ( 9747b2...519d4a )
by Dmitry
15:56
created

Bill::attributeLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

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 14
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 11
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
use Yii;
15
16
class Bill extends \hipanel\base\Model
17
{
18
    use \hipanel\base\ModelTrait;
19
20
    public $time_from;
21
    public $time_till;
22
23
    const SCENARIO_CREATE = 'create';
24
    const SCENARIO_UPDATE = 'update';
25
    const SCENARIO_DELETE = 'delete';
26
27
    public static $i18nDictionary = 'hipanel/finance';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function rules()
33
    {
34
        return [
35
            [['client_id', 'seller_id', 'id'], 'integer'],
36
            [['object_id', 'tariff_id'], 'integer'],
37
            [['client', 'seller', 'bill'], 'safe'],
38
            [['domain', 'server'], 'safe'],
39
            [['sum', 'balance', 'quantity'], 'number'],
40
            [['currency', 'label', 'descr'], 'safe'],
41
            [['object', 'domains', 'tariff'], 'safe'],
42
            [['type', 'gtype', 'class'], 'safe'],
43
            [['class_label'], 'safe'],
44
            [['type_label', 'gtype_label'], 'safe'],
45
            [['time'], 'date', 'format' => 'php:d.m.Y H:i:s'],
46
47
            [['id'], 'required', 'on' => [self::SCENARIO_UPDATE, self::SCENARIO_DELETE]],
48
            [['client_id'], 'integer', 'on' => [self::SCENARIO_CREATE]],
49
            [['currency', 'sum', 'type', 'label'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
50
            [['client_id', 'sum', 'time'], 'required', 'on' => [self::SCENARIO_CREATE]],
51
            [['client'], 'safe', 'on' => [self::SCENARIO_CREATE]],
52
        ];
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function attributeLabels()
59
    {
60
        return $this->mergeAttributeLabels([
61
            'client' => Yii::t('hipanel', 'Client'),
62
            'time' => Yii::t('hipanel', 'Time'),
63
            'currency' => Yii::t('hipanel', 'Currency'),
64
            'balance' => Yii::t('hipanel', 'Balance'),
65
            'gtype' => Yii::t('hipanel', 'Type'),
66
            'gtype_label' => Yii::t('hipanel', 'Type'),
67
            'sum' => Yii::t('hipanel/finance', 'Sum'),
68
            'tariff' => Yii::t('hipanel/finance', 'Tariff'),
69
            'tariff_id' => Yii::t('hipanel/finance', 'Tariff'),
70
        ]);
71
    }
72
73
    public function prepareToCopy()
74
    {
75
        $this->id = null;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<hipanel\modules\finance\models\Bill>. 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...
76
        $this->setIsNewRecord(true);
77
78
        return true;
79
    }
80
}
81