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.
Test Setup Failed
Push — filters ( fb817b...44fc4f )
by
unknown
11:13
created

DefaultController::actionAutoCompleteSearch()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 30
Code Lines 20

Duplication

Lines 3
Ratio 10 %
Metric Value
dl 3
loc 30
rs 8.8571
cc 3
eloc 20
nc 4
nop 1
1
<?php
2
3
namespace app\controllers;
4
5
use app\actions\SubmitFormAction;
6
use app\backend\actions\PropertyHandler;
7
use app\models\Form;
8
use app\modules\core\components\MailComponent;
9
use app\modules\shop\models\Product;
10
use app\models\Search;
11
use app\modules\seo\behaviors\MetaBehavior;
12
use Yii;
13
use yii\helpers\Url;
14
use yii\web\Controller;
15
use yii\web\Response;
16
17
class DefaultController extends Controller
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public function actions()
23
    {
24
        return [
25
            'error' => [
26
                'class' => 'app\actions\ErrorAction',
27
            ],
28
            'captcha' => [
29
                'class' => 'yii\captcha\CaptchaAction',
30
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
31
            ],
32
            'submit-form' => [
33
                'class' => SubmitFormAction::className(),
34
            ],
35
//            '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...
36
//                'class' => PropertyHandler::className(),
37
//                'modelName' => Form::className()
38
//            ]
39
        ];
40
    }
41
42
    public function actionIndex()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43
    {
44
        return $this->render('index');
45
    }
46
47
48
    public function actionSearch()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        $model = new Search();
51
        $model->load(Yii::$app->request->get());
52
        return $this->render(
53
            'search',
54
            [
55
                'model' => $model,
56
            ]
57
        );
58
    }
59
60
    /**
61
     * @param $term
62
     * @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...
63
     */
64
    public function actionAutoCompleteSearch($term)
65
    {
66
        Yii::$app->response->format = Response::FORMAT_JSON;
67
        $query = Product::find()
68
            ->select(['id', 'name', 'main_category_id', 'slug', 'sku'])
69
            ->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_DESC]);
70 View Code Duplication
        foreach (['name', 'content', 'sku'] as $attribute) {
71
            $query->orWhere(['like', $attribute, $term]);
72
        }
73
        $query->andWhere(['active'=>1]);
74
        $products = $query->limit(Yii::$app->getModule('core')->autoCompleteResultsCount)->all();
75
        $result = [];
76
77
        foreach ($products as $product) {
78
            /** @var Product $product */
79
            $result[] = [
80
                'id' => $product->id,
81
                'name' => $product->name,
82
                'url' => Url::toRoute(
83
                    [
84
                        '@product',
85
                        'model' => $product,
86
                        'category_group_id' => $product->getMainCategory()->category_group_id,
87
                    ],
88
                    true
89
                ),
90
            ];
91
        }
92
        return $result;
93
    }
94
}
95