Completed
Push — master ( b7b6b7...d64e0b )
by Dmitry
14:34
created

OrderController::actionXenSsd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\server\controllers;
4
5
use hipanel\base\CrudController;
6
use hipanel\modules\server\cart\ServerOrderProduct;
7
use hipanel\modules\server\cart\Tariff;
8
use hipanel\modules\server\helpers\ServerHelper;
9
use hiqdev\yii2\cart\actions\AddToCartAction;
10
use Yii;
11
12
class OrderController extends CrudController
13
{
14
    public function actions()
15
    {
16
        return [
17
            'add-to-cart' => [
18
                'class' => AddToCartAction::class,
19
                'productClass' => ServerOrderProduct::class
20
            ]
21
        ];
22
    }
23
24
    public function actionOrder($id)
25
    {
26
        $package = ServerHelper::getAvailablePackages(null, $id);
27
        $osImages = ServerHelper::getOsimages($package->tariff->type);
28
29
        return $this->render('order', [
30
            'package' => $package,
31
            'product' => new ServerOrderProduct(['tariff_id' => $package->tariff->id]),
32
            '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 27 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...
33
            'panels' => ServerHelper::getPanels(),
34
        ]);
35
    }
36
37
    public function actionIndex()
38
    {
39
        return $this->actionXenSsd();
40
    }
41
42 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...
43
    {
44
        return $this->render('xen_ssd', [
45
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_XEN),
46
            'tariffTypes' => Yii::$app->params['vdsproduct'],
47
        ]);
48
    }
49
50 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...
51
    {
52
        return $this->render('xen_ssd', [
53
            'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_OPENVZ),
54
            'tariffTypes' => Yii::$app->params['vdsproduct'],
55
        ]);
56
    }
57
58
    public function actionTariffsDetails()
59
    {
60
        return $this->render('tariffs_details');
61
    }
62
63
    public function actionAdvantages()
64
    {
65
        return $this->render('advantages');
66
    }
67
68
    public function actionWhatIsVds()
69
    {
70
        return $this->render('what_is_vds');
71
    }
72
}
73