Completed
Pull Request — master (#19)
by
unknown
05:45
created

OrderController::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Server module for HiPanel.
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\controllers;
12
13
use hipanel\base\CrudController;
14
use hipanel\modules\finance\models\Tariff;
15
use hipanel\modules\server\cart\ServerOrderProduct;
16
use hipanel\modules\server\helpers\ServerHelper;
17
use hipanel\filters\EasyAccessControl;
18
use hiqdev\yii2\cart\actions\AddToCartAction;
19
use Yii;
20
21
class OrderController extends CrudController
22
{
23
    public function behaviors()
24
    {
25
        return array_merge(parent::behaviors(), [
26
            [
27
                'class' => EasyAccessControl::class,
28
                'actions' => [
29
                    'add-to-cart' => 'server.pay',
30
                    '*' => 'server.read',
31
                ],
32
            ],
33
        ]);
34
    }
35
36
    public function actions()
37
    {
38
        return [
39
            'add-to-cart' => [
40
                'class' => AddToCartAction::class,
41
                'productClass' => ServerOrderProduct::class,
42
                'redirectToCart' => true,
43
            ],
44
        ];
45
    }
46
47
    public function actionOrder($id)
48
    {
49
        $package = ServerHelper::getAvailablePackages(null, $id);
50
        $osImages = ServerHelper::getOsimages($package->tariff->type);
51
52
        return $this->render('order', [
53
            'package' => $package,
54
            'product' => new ServerOrderProduct(['tariff_id' => $package->tariff->id]),
55
            'groupedOsimages' => ServerHelper::groupOsimages($osImages),
0 ignored issues
show
Bug introduced by
It seems like $osImages defined by \hipanel\modules\server\...$package->tariff->type) on line 50 can also be of type null; however, hipanel\modules\server\h...Helper::groupOsimages() does only seem to accept array<integer,object<hip...server\models\Osimage>>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56
            'panels' => ServerHelper::getPanels(),
57
        ]);
58
    }
59
60
    public function actionIndex()
61
    {
62
        return $this->render('index');
63
    }
64
65 View Code Duplication
    public function actionXenSsd()
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...
66
    {
67
        return $this->render('xen_ssd', [
68
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_XEN),
69
            'tariffTypes' => Yii::$app->params['vdsproduct'],
70
        ]);
71
    }
72
73 View Code Duplication
    public function actionOpenVz()
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...
74
    {
75
        return $this->render('open_vz', [
76
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_OPENVZ),
77
            'tariffTypes' => Yii::$app->params['vdsproduct'],
78
        ]);
79
    }
80
81
    public function actionTariffsDetails()
82
    {
83
        return $this->render('tariffs_details');
84
    }
85
86
    public function actionAdvantages()
87
    {
88
        return $this->render('advantages');
89
    }
90
91
    public function actionWhatIsVds()
92
    {
93
        return $this->render('what_is_vds');
94
    }
95
}
96