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 ( d3bfca...80f711 )
by Alexander
10:26
created

ShopModule::getBackendGrids()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace app\modules\shop;
4
5
use app;
6
use app\backend\BackendModule;
7
use app\components\BaseModule;
8
use app\modules\shop\handlers\UserHandler;
9
use app\modules\shop\models\ConfigConfigurationModel;
10
use kartik\icons\Icon;
11
use Yii;
12
use yii\base\Application;
13
use yii\base\BootstrapInterface;
14
use yii\base\Event;
15
use yii\web\User;
16
17
/**
18
 * Shop module is the base core module of DotPlant2 CMS handling all common e-commerce features
19
 * @package app\modules\shop
20
 */
21
class ShopModule extends BaseModule implements BootstrapInterface, app\modules\event\interfaces\EventInterface
22
{
23
    const BACKEND_PRODUCT_GRID = 'productEditGrid';
24
    const BACKEND_CATEGORY_GRID = 'categoryEditGrid';
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public $controllerMap = [
30
        'backend-filter-sets' => 'app\modules\shop\backend\FilterSetsController',
31
        'backend-addons' => 'app\modules\shop\backend\AddonsController',
32
    ];
33
34
    /**
35
     * @var int How much products per page to show
36
     */
37
    public $productsPerPage = 15;
38
39
    /**
40
     * @var string How show products in category
41
     */
42
    public $listViewType = 'blockView';
43
    /**
44
     * @var int How much products allow to compare at once
45
     */
46
    public $maxProductsToCompare = 3;
47
48
    /**
49
     * @var bool Should we show and query for products of subcategories
50
     */
51
    public $showProductsOfChildCategories = 1;
52
53
    /**
54
     * @var int How much products to show on search results page
55
     */
56
    public $searchResultsLimit = 9;
57
58
    /**
59
     * @var boolean Possible to search generated products
60
     */
61
    public $allowSearchGeneratedProducts = 0;
62
63
    /***
64
     * @var bool registration Guest User In Cart as new user and send data on e-mail
65
     */
66
    public $registrationGuestUserInCart = 0;
67
68
    /**
69
     * @var bool Show delete order in backend
70
     */
71
    public $deleteOrdersAbility = 0;
72
73
    /**
74
     * @var bool Filtration works only on parent products but not their children
75
     */
76
    public $filterOnlyByParentProduct = true;
77
78
    /**
79
     * @var string Filtration mode
80
     */
81
    public $multiFilterMode = ConfigConfigurationModel::MULTI_FILTER_MODE_INTERSECTION;
82
83
    /**
84
     * @var int How much last viewed products ID's to store in session
85
     */
86
    public $maxLastViewedProducts = 9;
87
88
    /**
89
     * @var bool Allow to add same product in the order
90
     */
91
    public $allowToAddSameProduct = 0;
92
93
    /**
94
     * @var bool Count only unique products in the order
95
     */
96
    public $countUniqueProductsOnly = 1;
97
98
    /**
99
     * @var bool Count children products in the order
100
     */
101
    public $countChildrenProducts = 1;
102
103
    /**
104
     * @var int Default measure ID
105
     */
106
    public $defaultMeasureId = 1;
107
108
    /**
109
     * @var int Final order stage leaf
110
     */
111
    public $finalOrderStageLeaf = 0;
112
113
    /**
114
     * @var int Default filter for Orders by stage in backend
115
     */
116
    public $defaultOrderStageFilterBackend = 0;
117
118
    /**
119
     * @var int
120
     */
121
    public $showDeletedOrders = 0;
122
123
    /**
124
     * @var array
125
     */
126
    public $ymlConfig = [];
127
128
    /**
129
     * @var array
130
     */
131
    public $googleFeedConfig = [];
132
133
134
    /**
135
     * @var bool Show filter links in breadcrumbs
136
     */
137
    public $showFiltersInBreadcrumbs = false;
138
139
    /**
140
     * @var bool Use method ceilQuantity of Measure model
141
     */
142
    public $useCeilQuantity = true;
143
144
    /**
145
     * @var string View file for render product item content block
146
     */
147
    public $itemView = '@app/modules/shop/views/product/item-row';
148
149
    /**
150
     * @var string View file for render product list content block
151
     */
152
    public $listView = '@app/modules/shop/views/product/item-list';
153
154
    /**
155
     * @inheritdoc
156
     */
157
    public function behaviors()
158
    {
159
        return [
160
            'configurableModule' => [
161
                'class' => 'app\modules\config\behaviors\ConfigurableModuleBehavior',
162
                'configurationView' => '@app/modules/shop/views/configurable/_config',
163
                'configurableModel' => 'app\modules\shop\models\ConfigConfigurationModel',
164
            ]
165
        ];
166
    }
167
168
    /**
169
     * Bootstrap method to be called during application bootstrap stage.
170
     * @param Application $app the application currently running
171
     */
172
    public function bootstrap($app)
173
    {
174
        /**
175
         * Move orders/order params from guest to logged/signed user
176
         */
177
        Event::on(
178
            User::className(),
179
            User::EVENT_AFTER_LOGIN,
180
            [UserHandler::className(), 'moveOrdersGuestToRegistered']
181
        );
182
183
        /**
184
         * Move wishlists/wishlist params from guest to logged/signed user
185
         */
186
        Event::on(
187
            User::className(),
188
            User::EVENT_AFTER_LOGIN,
189
            [UserHandler::className(), 'moveWishlistsGuestToRegistered']
190
        );
191
    }
192
193
    /**
194
     * @inheritdoc
195
     */
196
    public function init()
197
    {
198
        parent::init();
199
        if (Yii::$app instanceof \yii\console\Application) {
0 ignored issues
show
Bug introduced by
The class yii\console\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
200
            $this->controllerMap = [];
201
        }
202
    }
203
204
    /** @inheritdoc */
205
    public function getBackendGrids()
206
    {
207
        return [
208
            [
209
                'defaultValue' => BackendModule::BACKEND_GRID_ONE_TO_ONE,
210
                'key' => self::BACKEND_PRODUCT_GRID,
211
                'label' => Yii::t('app', 'Product edit'),
212
            ],
213
            [
214
                'defaultValue' => BackendModule::BACKEND_GRID_ONE_TO_ONE,
215
                'key' => self::BACKEND_CATEGORY_GRID,
216
                'label' => Yii::t('app', 'Category edit'),
217
            ],
218
        ];
219
    }
220
221
    /**
222
     * @return void
223
     */
224
    public static function attachEventsHandlers()
0 ignored issues
show
Coding Style introduced by
attachEventsHandlers uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
225
    {
226
        Event::on(
227
            app\modules\floatPanel\widgets\FloatingPanel::class,
228
            app\modules\floatPanel\widgets\FloatingPanel::EVENT_BEFORE_RENDER,
229
            function ($event) {
230
                switch (Yii::$app->requestedRoute) {
231
                    case 'shop/product/list':
232
                        if (isset($_GET['properties'])) {
233
                            $apply_if_params = [];
234
                            foreach ($_GET['properties'] as $property_id => $values) {
235
                                if (isset($values[0])) {
236
                                    $apply_if_params[$property_id] = $values[0];
237
                                }
238
                            }
239
                            if (Yii::$app->response->dynamic_content_trait === true) {
240
                                $event->items[] = [
241
                                    'label' => Icon::show('puzzle') . ' ' . Yii::t('app', 'Edit Dynamic Content'),
242
                                    'url' => [
243
                                        '/backend/dynamic-content/edit',
244
                                        'id' => Yii::$app->response->matched_dynamic_content_trait_model->id,
245
                                    ],
246
                                ];
247
                            } else {
248
                                if (isset($_GET['properties'], $_GET['last_category_id'])) {
249
                                    $event->items[] = [
250
                                        'label' => Icon::show('puzzle') . ' ' . Yii::t('app', 'Add Dynamic Content'),
251
                                        'url' => [
252
                                            '/backend/dynamic-content/edit',
253
                                            'DynamicContent' => [
254
                                                'apply_if_params' => Json::encode($apply_if_params),
255
                                                'apply_if_last_category_id' => $_GET['last_category_id'],
256
                                                'object_id' => Object::getForClass(app\modules\shop\models\Product::className())->id,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
257
                                                'route' => 'shop/product/list',
258
                                            ]
259
                                        ],
260
                                    ];
261
262
                                }
263
264
                            }
265 View Code Duplication
                        } else {
266
                            // no properties selected - go to category edit page
267
                            if (isset($_GET['last_category_id'])) {
268
                                $cat = app\modules\shop\models\Category::findById($_GET['last_category_id']);
269
                                $event->items[] = [
270
                                    'label' => Icon::show('pencil') . ' ' . Yii::t('app', 'Edit category'),
271
                                    'url' => [
272
                                        '/shop/backend-category/edit',
273
                                        'id' => $cat->id,
274
                                        'parent_id' => $cat->parent_id,
275
                                    ],
276
                                ];
277
                            }
278
                        }
279
                        break;
280
                    case 'shop/product/show':
281
                        if (isset($_GET['model_id'])) {
282
                            $event->items[] = [
283
                                'label' => Icon::show('pencil') . ' ' . Yii::t('app', 'Edit product'),
284
                                'url' => [
285
                                    '/shop/backend-product/edit',
286
                                    'id' => intval($_GET['model_id'])
287
                                ],
288
                            ];
289
                        }
290
                        break;
291
                }
292
            }
293
        );
294
    }
295
}
296