Completed
Push — master ( d64e0b...62d54f )
by Dmitry
15:28
created

ServerOrderPurchase::execute()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.2
cc 4
eloc 7
nc 3
nop 0
crap 20
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
use hipanel\modules\finance\cart\PendingPurchaseException;
16
use Yii;
17
18
/**
19
 * Class ServerOrderPurchase.
20
 */
21
class ServerOrderPurchase extends AbstractServerPurchase
22
{
23
    use ModelTrait;
24
25
    /** {@inheritdoc} */
26
    public static function operation()
27
    {
28
        return 'Buy';
29
    }
30
31
    /** {@inheritdoc} */
32
    public function init()
33
    {
34
        parent::init();
35
36
        $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...
37
    }
38
39 View Code Duplication
    public function rules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        return array_merge(parent::rules(), [
42
            [['osimage', 'cluster_id', 'purpose', 'tariff_id'], 'required'],
43
            [['osimage', 'panel', 'social', 'purpose'], 'safe'],
44
            [['tariff_id', 'cluster_id'], 'integer'],
45
        ]);
46
    }
47
48
    public function execute()
49
    {
50
        if (parent::execute()) {
51
            Yii::$app->getView()->params['remarks'][] = Yii::t('hipanel/server/order', 'You will receive an email with server access information right after setup.');
52
53
            if (is_array($this->_result) && isset($this->_result['_action_pending'])) {
54
                throw new PendingPurchaseException(Yii::t('hipanel/server/order', 'Server setup will be performed as soon as manager confirms your account verification. Please wait.'), $this->position);
55
            }
56
57
            return true;
58
        }
59
60
        return false;
61
    }
62
63
    public function renderNotes()
64
    {
65
66
    }
67
}
68