GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Helper::getReturnUrl()   B
last analyzed

Complexity

Conditions 10
Paths 5

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 7.6666
c 0
b 0
f 0
cc 10
nc 5
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace app\backend\components;
4
5
use app\backend\BackendModule;
6
use app\components\BaseModule;
7
use Yii;
8
use yii\db\ActiveRecord;
9
use yii\helpers\Html;
10
use kartik\icons\Icon;
11
12
class Helper
13
{
14
    private static $returnUrl;
15
    public static $returnUrlWithoutHistory = false;
16
17
    /**
18
     * @param int $depth
0 ignored issues
show
Bug introduced by
There is no parameter named $depth. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
     * @return string
20
     */
21
    public static function getReturnUrl()
22
    {
23
        if (is_null(self::$returnUrl)) {
24
            $url = parse_url(Yii::$app->request->url);
25
            $returnUrlParams = [];
26
            if (isset($url['query'])) {
27
                $parts = explode('&', $url['query']);
28
                foreach ($parts as $part) {
29
                    $pieces = explode('=', $part);
30
                    if (static::$returnUrlWithoutHistory && count($pieces) == 2 && $pieces[0] === 'returnUrl') {
31
                        continue;
32
                    }
33
                    if (count($pieces) == 2 && strlen($pieces[1]) > 0) {
34
                        $returnUrlParams[] = $part;
35
                    }
36
                }
37
            }
38
            if (count($returnUrlParams) > 0) {
39
                self::$returnUrl = $url['path'] . '?' . implode('&', $returnUrlParams);
40
            } else {
41
                self::$returnUrl = $url['path'];
42
            }
43
        }
44
        return self::$returnUrl;
45
    }
46
47
    /**
48
     * @param ActiveRecord $model Model instance
49
     * @param string $indexAction Route path to index action
50
     * @return string Rendered save buttons with redurectUrl!
51
     */
52
    public static function saveButtons(ActiveRecord $model, $indexAction='index', $buttonClass='btn-sm', $onlySaveAndBack=false)
53
    {
54
        $result = '<div class="form-group no-margin btn-group">';
55
        if ($onlySaveAndBack === false) {
56
            $result .=
57
                Html::a(
58
                    Icon::show('arrow-circle-left') . Yii::t('app', 'Back'),
59
                    Yii::$app->request->get('returnUrl', [$indexAction, 'id' => $model->id]),
60
                    ['class' => 'btn btn-default ' . $buttonClass]
61
                );
62
        }
63
64 View Code Duplication
        if ($model->isNewRecord && $onlySaveAndBack === false) {
65
            $result .= Html::submitButton(
66
                Icon::show('save') . Yii::t('app', 'Save & Go next'),
67
                [
68
                    'class' => 'btn btn-success ' . $buttonClass,
69
                    'name' => 'action',
70
                    'value' => 'next',
71
                ]
72
            );
73
        }
74
75
        $result .=
76
            Html::submitButton(
77
                Icon::show('save') . Yii::t('app', 'Save & Go back'),
78
                [
79
                    'class' => 'btn btn-warning ' . $buttonClass,
80
                    'name' => 'action',
81
                    'value' => 'back',
82
                ]
83
            );
84 View Code Duplication
        if ($onlySaveAndBack === false) {
85
            $result .=
86
                Html::submitButton(
87
                    Icon::show('save') . Yii::t('app', 'Save'),
88
                    [
89
                        'class' => 'btn btn-primary ' . $buttonClass,
90
                        'name' => 'action',
91
                        'value' => 'save',
92
                    ]
93
                );
94
        }
95
        $result .= '</div>';
96
97
        return $result;
98
    }
99
100
    public static function toString($value)
101
    {
102
        return (string) $value;
103
    }
104
105
    public static function getBackendGridClass($moduleId, $key, $columnNumber, $defaultClass = '')
106
    {
107
        /** @var BackendModule $backendModule */
108
        $backendModule = Yii::$app->getModule('backend');
109
        if (isset($backendModule->backendEditGrids[$moduleId][$key])) {
110
            $type = $backendModule->backendEditGrids[$moduleId][$key];
111
        } else {
112
            /** @var BaseModule $module */
113
            $module = Yii::$app->getModule($moduleId);
114
            if ($module->hasMethod('getBackendGridDefaultValue')) {
115
                $type = $module->getBackendGridDefaultValue($key);
116
            } else {
117
                return $defaultClass;
118
            }
119
        }
120
        switch ($type) {
121
            case BackendModule::BACKEND_GRID_ONE_COLUMN:
122
                return 'backend-edit-grid col-lg-12 col-md-12 col-ms-12 col-xs-12';
123
            case BackendModule::BACKEND_GRID_ONE_TO_ONE:
124
                return 'backend-edit-grid col-lg-6 col-md-6 col-ms-6 col-xs-12';
125
            case BackendModule::BACKEND_GRID_TWO_TO_ONE:
126
                return $columnNumber === 1
127
                    ? 'backend-edit-grid col-lg-8 col-md-8 col-ms-8 col-xs-12'
128
                    : 'backend-edit-grid col-lg-4 col-md-4 col-ms-4 col-xs-12';
129
            case BackendModule::BACKEND_GRID_ONE_TO_TWO:
130
                return $columnNumber === 1
131
                    ? 'backend-edit-grid col-lg-4 col-md-4 col-ms-4 col-xs-12'
132
                    : 'backend-edit-grid col-lg-8 col-md-8 col-ms-8 col-xs-12';
133
            default:
134
                return $defaultClass;
135
        }
136
    }
137
}
138