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

ReviewModule::attachEventsHandlers()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 43
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
rs 8.439
cc 6
eloc 31
nc 1
nop 0
1
<?php
2
3
namespace app\modules\review;
4
5
use app\components\BaseModule;
6
use app\models\Object;
7
use app\modules\event\interfaces\EventInterface;
8
use app\modules\floatPanel\widgets\FloatingPanel;
9
use app\modules\page\models\Page;
10
use app\modules\review\models\Review;
11
use app\modules\shop\models\Category;
12
use app\modules\shop\models\Product;
13
use kartik\icons\Icon;
14
use yii\base\Event;
15
16
/**
17
 * Base configuration module for DotPlant2 CMS
18
 * @package app\modules\review
19
 */
20
class ReviewModule extends BaseModule implements EventInterface
21
{
22
    /**
23
     * @var int Max reviews on page
24
     */
25
    public $maxPerPage = 10;
26
27
    /**
28
     * @var int Default number of reviews on page
29
     */
30
    public $pageSize = 10;
31
32
    /**
33
     * @var bool Enable spam checking
34
     */
35
    public $enableSpamChecking = false;
36
37
    /**
38
     * @return array the behavior configurations.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,string>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
39
     */
40
    public function behaviors()
41
    {
42
        return [
43
            'configurableModule' => [
44
                'class' => 'app\modules\config\behaviors\ConfigurableModuleBehavior',
45
                'configurationView' => '@app/modules/review/views/configurable/_config',
46
                'configurableModel' => 'app\modules\review\models\ConfigConfigurationModel',
47
            ]
48
        ];
49
    }
50
51
    /**
52
     * @return void
53
     */
54
    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...
55
    {
56
        Event::on(
57
            FloatingPanel::class,
58
            FloatingPanel::EVENT_BEFORE_RENDER,
59
            function ($event) {
60
                $objectId = 0;
61
                $modelId = 0;
62
63
                switch (\Yii::$app->requestedRoute) {
64
                    case "shop/product/show":
65
                        $objectId = Object::getForClass(Product::class)->id;
66
                        $modelId = $_GET['model_id'];
67
                        break;
68
69
                    case "shop/product/list":
70
                        $objectId = Object::getForClass(Category::class)->id;
71
                        $modelId = $_GET['last_category_id'];
72
                        break;
73
74
                    case "/page/page/show":
75
                    case "/page/page/list":
76
                        $objectId = Object::getForClass(Page::class)->id;
77
                        $modelId = $_GET['id'];
78
                        break;
79
                }
80
                $reviews = Review::getForObjectModel($modelId, $objectId, 1);
81
                if (!empty($reviews)) {
82
                    $event->items[] = [
83
                        "label" => Icon::show("pencil") . \Yii::t("app", "Edit reviews") . " (" . count($reviews) . ")",
84
                        "url" => [
85
                            "/review/backend-review/index",
86
                            "SearchModel" => [
87
                                "object_id" => $objectId,
88
                                "object_model_id" => $modelId
89
                            ]
90
                        ],
91
                        "target" => "_blank"
92
                    ];
93
                }
94
            }
95
        );
96
    }
97
}
98