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.
Passed
Push — master ( 63d69c...adb150 )
by
unknown
10:11
created

m160620_112036_config_fix_parent_only::down()   B

Complexity

Conditions 9
Paths 16

Size

Total Lines 54
Code Lines 37

Duplication

Lines 45
Ratio 83.33 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 45
loc 54
rs 7.255
cc 9
eloc 37
nc 16
nop 0

How to fix   Long Method   

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
use app\modules\shop\models\ConfigConfigurationModel;
4
use yii\db\Migration;
5
use yii\helpers\ArrayHelper;
6
7
class m160620_112036_config_fix_parent_only extends Migration
8
{
9
    public function up()
10
    {
11
        $fileName = Yii::getAlias('@app/config/web-configurables.php');
12 View Code Duplication
        if (true === is_file($fileName)) {
13
            $array = include_once($fileName);
14
            if (true === is_array($array) &&
15
                null !== $onlyParent = ArrayHelper::getValue($array, 'modules.shop.filterOnlyByParentProduct', null)
16
            ) {
17
                unset($array['modules']['shop']['filterOnlyByParentProduct']);
18
                $array['modules']['shop']['productsFilteringMode'] = $onlyParent === true ?
19
                    ConfigConfigurationModel::FILTER_PARENTS_ONLY :
20
                    ConfigConfigurationModel::FILTER_CHILDREN_ONLY;
21
22
                $writer = new \app\modules\config\helpers\ApplicationConfigWriter([
23
                    'filename' => '@app/config/web-configurables.php',
24
                    'loadExistingConfiguration' => false,
25
                ]);
26
                $writer->addValues($array);
27
                $writer->commit();
28
29
            } else {
30
                echo "file @app/config/web-configurables.php cannot be changed. \n";
31
            }
32
        }
33
34
35
        $shopFilename = Yii::getAlias('@app/config/configurables-state/shop.php');
36 View Code Duplication
        if (true === file_exists($shopFilename)) {
37
            $shopConfigurablesArray = include($shopFilename);
38
            if (true === is_array($shopConfigurablesArray) &&
39
                null !== $onlyParent = ArrayHelper::getValue($shopConfigurablesArray, 'filterOnlyByParentProduct', null)
40
            ) {
41
                unset($shopConfigurablesArray['filterOnlyByParentProduct']);
42
                $shopConfigurablesArray['productsFilteringMode'] = $onlyParent === true ?
43
                    ConfigConfigurationModel::FILTER_PARENTS_ONLY :
44
                    ConfigConfigurationModel::FILTER_CHILDREN_ONLY;
45
                $writer = new \app\modules\config\helpers\ApplicationConfigWriter([
46
                    'filename' => '@app/config/configurables-state/shop.php',
47
                    'loadExistingConfiguration' => false,
48
                ]);
49
                $writer->addValues($shopConfigurablesArray);
50
                $writer->commit();
51
            } else {
52
                echo " file@app/config/configurables-state/shop.php cannot be changed. \n";
53
            }
54
        }
55
56
    }
57
58
    public function down()
59
    {
60
        $fileName = Yii::getAlias('@app/config/web-configurables.php');
61 View Code Duplication
        if (true === is_file($fileName)) {
62
            $array = include_once($fileName);
63
            if (true === is_array($array) &&
64
                null !== $productsFilteringMode = ArrayHelper::getValue($array,
65
                    'modules.shop.productsFilteringMode', null)
66
            ) {
67
                unset($array['modules']['shop']['productsFilteringMode']);
68
                $array['modules']['shop']['filterOnlyByParentProduct'] =
69
                    $productsFilteringMode !== ConfigConfigurationModel::FILTER_CHILDREN_ONLY ?
70
                        true :
71
                        false;
72
73
                $writer = new \app\modules\config\helpers\ApplicationConfigWriter([
74
                    'filename' => '@app/config/web-configurables.php',
75
                    'loadExistingConfiguration' => false,
76
                ]);
77
                $writer->addValues($array);
78
                $writer->commit();
79
80
            } else {
81
                echo "file @app/config/web-configurables.php cannot be revert. \n";
82
            }
83
        }
84
85
86
        $shopFilename = Yii::getAlias('@app/config/configurables-state/shop.php');
87 View Code Duplication
        if (true === file_exists($shopFilename)) {
88
            $shopConfigurablesArray = include($shopFilename);
89
            if (true === is_array($shopConfigurablesArray) &&
90
                null !== $productsFilteringMode = ArrayHelper::getValue($shopConfigurablesArray,
91
                    'productsFilteringMode', null)
92
            ) {
93
                unset($shopConfigurablesArray['productsFilteringMode']);
94
                $shopConfigurablesArray['filterOnlyByParentProduct'] =
95
                    $productsFilteringMode !== ConfigConfigurationModel::FILTER_CHILDREN_ONLY ?
96
                        true :
97
                        false;
98
99
                $writer = new \app\modules\config\helpers\ApplicationConfigWriter([
100
                    'filename' => '@app/config/configurables-state/shop.php',
101
                    'loadExistingConfiguration' => false,
102
                ]);
103
                $writer->addValues($shopConfigurablesArray);
104
                $writer->commit();
105
            } else {
106
                echo "file @app/config/configurables-state/shop.php cannot be revert. \n";
107
            }
108
        }
109
110
111
    }
112
}
113