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   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 106
Duplicated Lines 80.19 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 18
c 2
b 0
f 1
lcom 1
cbo 1
dl 85
loc 106
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C up() 40 48 9
B down() 45 54 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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