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.

DefaultController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace app\controllers;
4
5
use app\actions\SubmitFormAction;
6
use app\components\search\SearchEvent;
7
use app\models\Search;
8
use app\modules\shop\models\Product;
9
use Yii;
10
use yii\helpers\Url;
11
use yii\web\Controller;
12
use yii\web\Response;
13
14
class DefaultController extends Controller
15
{
16
    /**
17
     * @inheritdoc
18
     */
19
    public function actions()
20
    {
21
        return [
22
            'error' => [
23
                'class' => 'app\actions\ErrorAction',
24
            ],
25
            'captcha' => [
26
                'class' => 'yii\captcha\CaptchaAction',
27
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
28
            ],
29
            'submit-form' => [
30
                'class' => SubmitFormAction::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
31
            ],
32
        ];
33
    }
34
35 View Code Duplication
    public function behaviors()
36
    {
37
        return [
38
            'verbs' => [
39
                'class' => \yii\filters\VerbFilter::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
40
                'actions' => [
41
                    'submit-form' => ['post'],
42
                ],
43
            ]
44
        ];
45
    }
46
47
    public function actionIndex()
48
    {
49
        return $this->render('index');
50
    }
51
52
53
    public function actionSearch()
54
    {
55
        $model = new Search();
56
        $model->load(Yii::$app->request->get());
57
        return $this->render(
58
            'search',
59
            [
60
                'model' => $model,
61
            ]
62
        );
63
    }
64
65
    /**
66
     * @param $term
67
     * @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...
68
     */
69
    public function actionAutoCompleteSearch($term)
70
    {
71
        Yii::$app->response->format = Response::FORMAT_JSON;
72
        $search = new Search();
73
        $search->q = $term;
74
        $search->on(Search::QUERY_SEARCH_PRODUCTS_BY_DESCRIPTION, function (SearchEvent $event) {
75
            $event->setFunctionSearch(function ($activeQuery) {
76
                $activeQuery->limit(Yii::$app->getModule('core')->autoCompleteResultsCount);
77
                $product = Yii::$container->get(Product::class);
78
                return $product::find()
79
                    ->select(['id', 'name', 'main_category_id', 'slug', 'sku'])
80
                    ->where(['id' => $activeQuery->all()])
81
                    ->all();
82
            });
83
        });
84
        $products = $search->searchProductsByDescription();
85
        $result = [];
86
87
        foreach ($products as $product) {
88
            /** @var Product $product */
89
            $result[] = [
90
                'id' => $product->id,
91
                'name' => $product->name,
92
                'url' => Url::toRoute(
93
                    [
94
                        '@product',
95
                        'model' => $product,
96
                        'category_group_id' => $product->getMainCategory()->category_group_id,
97
                    ],
98
                    true
99
                ),
100
            ];
101
        }
102
        return $result;
103
    }
104
}
105