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 — filters-dev ( b32603 )
by
unknown
11:53
created

DefaultController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 11.7 %

Coupling/Cohesion

Components 0
Dependencies 10

Importance

Changes 6
Bugs 4 Features 1
Metric Value
wmc 7
lcom 0
cbo 10
dl 11
loc 94
rs 10
c 6
b 4
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 4 1
A actions() 0 19 2
A behaviors() 11 11 1
A actionSearch() 0 11 1
B actionAutoCompleteSearch() 0 34 2

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
namespace app\controllers;
4
5
use app\actions\SubmitFormAction;
6
use app\backend\actions\PropertyHandler;
7
use app\components\search\SearchEvent;
8
use app\models\Form;
9
use app\models\Search;
10
use app\modules\core\components\MailComponent;
11
use app\modules\shop\models\Product;
12
use app\modules\seo\behaviors\MetaBehavior;
13
use Yii;
14
use yii\helpers\Url;
15
use yii\web\Controller;
16
use yii\web\Response;
17
18
class DefaultController extends Controller
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function actions()
24
    {
25
        return [
26
            'error' => [
27
                'class' => 'app\actions\ErrorAction',
28
            ],
29
            'captcha' => [
30
                'class' => 'yii\captcha\CaptchaAction',
31
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
32
            ],
33
            'submit-form' => [
34
                'class' => SubmitFormAction::className(),
35
            ],
36
//            'property-handler' => [
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
//                'class' => PropertyHandler::className(),
38
//                'modelName' => Form::className()
39
//            ]
40
        ];
41
    }
42
43 View Code Duplication
    public function behaviors()
44
    {
45
        return [
46
            'verbs' => [
47
                'class' => \yii\filters\VerbFilter::className(),
48
                'actions' => [
49
                    'submit-form' => ['post'],
50
                ],
51
            ]
52
        ];
53
    }
54
55
    public function actionIndex()
56
    {
57
        return $this->render('index');
58
    }
59
60
61
    public function actionSearch()
62
    {
63
        $model = new Search();
64
        $model->load(Yii::$app->request->get());
65
        return $this->render(
66
            'search',
67
            [
68
                'model' => $model,
69
            ]
70
        );
71
    }
72
73
    /**
74
     * @param $term
75
     * @return string JSON
0 ignored issues
show
Documentation introduced by
Should the return type not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
76
     */
77
    public function actionAutoCompleteSearch($term)
78
    {
79
        Yii::$app->response->format = Response::FORMAT_JSON;
80
        $search = new Search();
81
        $search->q = $term;
82
        $search->on(Search::QUERY_SEARCH_PRODUCTS_BY_DESCRIPTION, function (SearchEvent $event) {
83
            $event->setFunctionSearch(function ($activeQuery) {
84
                $activeQuery->limit(Yii::$app->getModule('core')->autoCompleteResultsCount);
85
                return Product::find()
86
                    ->select(['id', 'name', 'main_category_id', 'slug', 'sku'])
87
                    ->where(['id' => $activeQuery->all()])
88
                    ->all();
89
            });
90
        });
91
        $products = $search->searchProductsByDescription();
92
        $result = [];
93
94
        foreach ($products as $product) {
95
            /** @var Product $product */
96
            $result[] = [
97
                'id' => $product->id,
98
                'name' => $product->name,
99
                'url' => Url::toRoute(
100
                    [
101
                        '@product',
102
                        'model' => $product,
103
                        'category_group_id' => $product->getMainCategory()->category_group_id,
104
                    ],
105
                    true
106
                ),
107
            ];
108
        }
109
        return $result;
110
    }
111
}
112