Completed
Push — master ( 441ca2...ee333a )
by Dmitry
04:29
created

ServerOrderPurchase::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Server module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-server
7
 * @package   hipanel-module-server
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\server\cart;
13
14
use hipanel\base\ModelTrait;
15
16
/**
17
 * Class ServerOrderPurchase
18
 * @package hipanel\modules\server\cart
19
 */
20
class ServerOrderPurchase extends AbstractServerPurchase
21
{
22
    use ModelTrait;
23
24
    /** {@inheritdoc} */
25
    public static function operation()
26
    {
27
        return 'Buy';
28
    }
29
30
    /** {@inheritdoc} */
31
    public function init()
32
    {
33
        parent::init();
34
35
        $this->amount = $this->position->getQuantity();
0 ignored issues
show
Documentation introduced by
The property amount does not exist on object<hipanel\modules\s...rt\ServerOrderPurchase>. 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...
36
    }
37
38
    public function rules()
39
    {
40
        return array_merge(parent::rules(), [
41
            [['osimage', 'panel', 'cluster_id', 'social', 'purpose', 'tariff_id'], 'required'],
42
            [['osimage', 'panel', 'social', 'purpose'], 'safe'],
43
            [['tariff_id', 'cluster_id'], 'integer']
44
        ]);
45
    }
46
}
47