Passed
Push — v1 ( eca0e2...a307d6 )
by Andrew
07:27 queued 04:35
created

Webperf::handleSiteRequest()   B

Complexity

Conditions 10
Paths 2

Size

Total Lines 46
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 46
rs 7.6666
c 0
b 0
f 0
cc 10
nc 2
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Webperf plugin for Craft CMS 3.x
4
 *
5
 * Monitor the performance of your webpages through real-world user timing data
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2018 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\webperf;
12
13
use nystudio107\webperf\models\Settings;
14
use nystudio107\webperf\services\DataSamples as DataSamplesService;
15
use nystudio107\webperf\services\Beacons as BeaconsService;
16
use nystudio107\webperf\variables\WebperfVariable;
17
use nystudio107\webperf\widgets\Metrics as MetricsWidget;
18
19
use Craft;
0 ignored issues
show
Bug introduced by
The type Craft was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use craft\base\Plugin;
0 ignored issues
show
Bug introduced by
The type craft\base\Plugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use craft\services\Plugins;
0 ignored issues
show
Bug introduced by
The type craft\services\Plugins was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use craft\events\PluginEvent;
0 ignored issues
show
Bug introduced by
The type craft\events\PluginEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use craft\events\RegisterComponentTypesEvent;
0 ignored issues
show
Bug introduced by
The type craft\events\RegisterComponentTypesEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use craft\events\RegisterUserPermissionsEvent;
0 ignored issues
show
Bug introduced by
The type craft\events\RegisterUserPermissionsEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use craft\events\RegisterUrlRulesEvent;
0 ignored issues
show
Bug introduced by
The type craft\events\RegisterUrlRulesEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use craft\helpers\UrlHelper;
0 ignored issues
show
Bug introduced by
The type craft\helpers\UrlHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use craft\services\Dashboard;
0 ignored issues
show
Bug introduced by
The type craft\services\Dashboard was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use craft\services\UserPermissions;
0 ignored issues
show
Bug introduced by
The type craft\services\UserPermissions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use craft\web\twig\variables\CraftVariable;
0 ignored issues
show
Bug introduced by
The type craft\web\twig\variables\CraftVariable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use craft\web\UrlManager;
0 ignored issues
show
Bug introduced by
The type craft\web\UrlManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use craft\web\View;
0 ignored issues
show
Bug introduced by
The type craft\web\View was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
33
use yii\base\Event;
0 ignored issues
show
Bug introduced by
The type yii\base\Event was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
35
/**
36
 * Class Webperf
37
 *
38
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 4
Loading history...
39
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
40
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 5
Loading history...
41
 *
42
 * @property  DataSamplesService $dataSamples
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 2
Loading history...
43
 * @property  BeaconsService      $beacons
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 2
Loading history...
44
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
45
class Webperf extends Plugin
46
{
47
    // Static Properties
48
    // =========================================================================
49
50
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
51
     * @var Webperf
52
     */
53
    public static $plugin;
54
55
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @var Settings
57
     */
58
    public static $settings;
59
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @var string
62
     */
63
    public static $renderType = 'html';
64
65
    // Public Properties
66
    // =========================================================================
67
68
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
69
     * @var string
70
     */
71
    public $schemaVersion = '1.0.0';
72
73
    // Public Methods
74
    // =========================================================================
75
76
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
77
     * @inheritdoc
78
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
79
    public function init()
80
    {
81
        parent::init();
82
        // Initialize properties
83
        self::$plugin = $this;
84
        self::$settings = Webperf::$plugin->getSettings();
85
        $this->name = Webperf::$settings->pluginName;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
86
        // Install event listeners
87
        $this->installEventListeners();
88
        // Load that we've loaded
89
        Craft::info(
90
            Craft::t(
91
                'webperf',
92
                '{name} plugin loaded',
93
                ['name' => $this->name]
94
            ),
95
            __METHOD__
96
        );
97
    }
98
99
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
100
     * @inheritdoc
101
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
102
    public function getSettingsResponse()
103
    {
104
        // Just redirect to the plugin settings page
105
        Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('webperf/settings'));
106
    }
107
108
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
109
     * @inheritdoc
110
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
111
    public function getCpNavItem()
112
    {
113
        $subNavs = [];
114
        $navItem = parent::getCpNavItem();
115
        $currentUser = Craft::$app->getUser()->getIdentity();
116
        // Only show sub-navs the user has permission to view
117
        if ($currentUser->can('webperf:dashboard')) {
118
            $subNavs['dashboard'] = [
119
                'label' => 'Dashboard',
120
                'url' => 'webperf/dashboard',
121
            ];
122
        }
123
        if ($currentUser->can('webperf:settings')) {
124
            $subNavs['settings'] = [
125
                'label' => 'Settings',
126
                'url' => 'webperf/settings',
127
            ];
128
        }
129
        $navItem = array_merge($navItem, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
130
            'subnav' => $subNavs,
131
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
132
133
        return $navItem;
134
    }
135
136
    // Protected Methods
137
    // =========================================================================
138
139
    /**
140
     * Install our event listeners.
141
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
142
    protected function installEventListeners()
143
    {
144
        $request = Craft::$app->getRequest();
145
        // Add in our event listeners that are needed for every request
146
        $this->installGlobalEventListeners();
147
        // Install only for non-console site requests
148
        if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
149
            $this->installSiteEventListeners();
150
        }
151
        // Install only for non-console Control Panel requests
152
        if ($request->getIsCpRequest() && !$request->getIsConsoleRequest()) {
153
            $this->installCpEventListeners();
154
        }
155
        // Handler: EVENT_AFTER_INSTALL_PLUGIN
156
        Event::on(
157
            Plugins::class,
158
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
159
            function (PluginEvent $event) {
160
                if ($event->plugin === $this) {
161
                    // Invalidate our caches after we've been installed
162
                    $this->clearAllCaches();
163
                    // Send them to our welcome screen
164
                    $request = Craft::$app->getRequest();
165
                    if ($request->isCpRequest) {
166
                        Craft::$app->getResponse()->redirect(UrlHelper::cpUrl(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
167
                            'webperf/dashboard',
168
                            [
169
                                'showWelcome' => true,
170
                            ]
171
                        ))->send();
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
172
                    }
173
                }
174
            }
175
        );
176
    }
177
178
    /**
179
     * Install global event listeners for all request types
180
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
181
    protected function installGlobalEventListeners()
182
    {
183
        // Handler: CraftVariable::EVENT_INIT
184
        Event::on(
185
            CraftVariable::class,
186
            CraftVariable::EVENT_INIT,
187
            function (Event $event) {
188
                /** @var CraftVariable $variable */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
189
                $variable = $event->sender;
190
                $variable->set('webperf', WebperfVariable::class);
191
            }
192
        );
193
        // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
194
        Event::on(
195
            Plugins::class,
196
            Plugins::EVENT_AFTER_LOAD_PLUGINS,
197
            function () {
198
                // Install these only after all other plugins have loaded
199
                $request = Craft::$app->getRequest();
200
                // Only respond to non-console site requests
201
                if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
202
                    $this->handleSiteRequest();
203
                }
204
                // Respond to Control Panel requests
205
                if ($request->getIsCpRequest() && !$request->getIsConsoleRequest()) {
206
                    $this->handleAdminCpRequest();
207
                }
208
            }
209
        );
210
    }
211
212
    /**
213
     * Install site event listeners for site requests only
214
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
215
    protected function installSiteEventListeners()
216
    {
217
        // Handler: UrlManager::EVENT_REGISTER_SITE_URL_RULES
218
        Event::on(
219
            UrlManager::class,
220
            UrlManager::EVENT_REGISTER_SITE_URL_RULES,
221
            function (RegisterUrlRulesEvent $event) {
222
                Craft::debug(
223
                    'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
224
                    __METHOD__
225
                );
226
                // Register our Control Panel routes
227
                $event->rules = array_merge(
228
                    $event->rules,
229
                    $this->customFrontendRoutes()
230
                );
231
            }
232
        );
233
    }
234
235
    /**
236
     * Install site event listeners for Control Panel requests only
237
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
238
    protected function installCpEventListeners()
239
    {
240
        // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES
241
        Event::on(
242
            UrlManager::class,
243
            UrlManager::EVENT_REGISTER_CP_URL_RULES,
244
            function (RegisterUrlRulesEvent $event) {
245
                Craft::debug(
246
                    'UrlManager::EVENT_REGISTER_CP_URL_RULES',
247
                    __METHOD__
248
                );
249
                // Register our Control Panel routes
250
                $event->rules = array_merge(
251
                    $event->rules,
252
                    $this->customAdminCpRoutes()
253
                );
254
            }
255
        );
256
        // Handler: Dashboard::EVENT_REGISTER_WIDGET_TYPES
257
        Event::on(
258
            Dashboard::class,
259
            Dashboard::EVENT_REGISTER_WIDGET_TYPES,
260
            function (RegisterComponentTypesEvent $event) {
261
                $event->types[] = MetricsWidget::class;
262
            }
263
        );
264
        // Handler: UserPermissions::EVENT_REGISTER_PERMISSIONS
265
        Event::on(
266
            UserPermissions::class,
267
            UserPermissions::EVENT_REGISTER_PERMISSIONS,
268
            function (RegisterUserPermissionsEvent $event) {
269
                Craft::debug(
270
                    'UserPermissions::EVENT_REGISTER_PERMISSIONS',
271
                    __METHOD__
272
                );
273
                // Register our custom permissions
274
                $event->permissions[Craft::t('webperf', 'Webperf')] = $this->customAdminCpPermissions();
275
            }
276
        );
277
    }
278
279
    /**
280
     * Handle site requests.  We do it only after we receive the event
281
     * EVENT_AFTER_LOAD_PLUGINS so that any pending db migrations can be run
282
     * before our event listeners kick in
283
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
284
    protected function handleSiteRequest()
285
    {
286
        // Don't include the beacon for response codes >= 400
287
        $response = Craft::$app->getResponse();
288
        if ($response->statusCode < 400) {
289
            // Handler: View::EVENT_END_PAGE
290
            Event::on(
291
                View::class,
292
                View::EVENT_END_PAGE,
293
                function () {
294
                    Craft::debug(
295
                        'View::EVENT_END_PAGE',
296
                        __METHOD__
297
                    );
298
                    $view = Craft::$app->getView();
299
                    // The page is done rendering, include our beacon
300
                    if (Webperf::$settings->includeBeacon && $view->getIsRenderingPageTemplate()) {
301
                        switch (self::$renderType) {
302
                            case 'html':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 28
Loading history...
303
                                Webperf::$plugin->beacons->includeHtmlBeacon();
304
                                break;
305
                            case 'amp-html':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 28
Loading history...
306
                                Webperf::$plugin->beacons->includeAmpHtmlScript();
307
                                break;
308
                        }
309
                    }
310
                }
311
            );
312
            // Handler: View::EVENT_END_BODY
313
            Event::on(
314
                View::class,
315
                View::EVENT_END_BODY,
316
                function () {
317
                    Craft::debug(
318
                        'View::EVENT_END_BODY',
319
                        __METHOD__
320
                    );
321
                    $view = Craft::$app->getView();
322
                    // The page is done rendering, include our beacon
323
                    if (Webperf::$settings->includeBeacon && $view->getIsRenderingPageTemplate()) {
324
                        switch (self::$renderType) {
325
                            case 'html':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 28
Loading history...
326
                                break;
327
                            case 'amp-html':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 24 spaces, found 28
Loading history...
328
                                Webperf::$plugin->beacons->includeAmpHtmlBeacon();
329
                                break;
330
                        }
331
                    }
332
                }
333
            );
334
        }
335
    }
336
337
    /**
338
     * Handle Control Panel requests. We do it only after we receive the event
339
     * EVENT_AFTER_LOAD_PLUGINS so that any pending db migrations can be run
340
     * before our event listeners kick in
341
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
342
    protected function handleAdminCpRequest()
343
    {
344
    }
345
346
    /**
347
     * Clear all the caches!
348
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
349
    public function clearAllCaches()
350
    {
351
    }
352
353
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
354
     * @inheritdoc
355
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
356
    protected function createSettingsModel()
357
    {
358
        return new Settings();
359
    }
360
361
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
362
     * @inheritdoc
363
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
364
    protected function settingsHtml(): string
365
    {
366
        return Craft::$app->view->renderTemplate(
367
            'webperf/settings',
368
            [
369
                'settings' => $this->getSettings()
370
            ]
371
        );
372
    }
373
374
    /**
375
     * Return the custom frontend routes
376
     *
377
     * @return array
378
     */
379
    protected function customFrontendRoutes(): array
380
    {
381
        return [
382
            // Beacon
383
            '/webperf/metrics/beacon' => 'webperf/metrics/beacon',
384
            // Tables
385
            '/webperf/tables/dashboard' => 'webperf/tables/dashboard',
386
            '/webperf/tables/redirects' => 'webperf/tables/redirects',
387
            // Charts
388
            '/webperf/charts/dashboard-radial-bar/<range:{handle}>/<column:{handle}>' => 'webperf/charts/dashboard-radial-bar',
389
            '/webperf/charts/dashboard-radial-bar/<range:{handle}>/<column:{handle}>/<siteId:\d+>' => 'webperf/charts/dashboard-radial-bar',
390
            '/webperf/charts/widget/<days>' => 'webperf/charts/widget',
391
        ];
392
    }
393
    /**
394
     * Return the custom Control Panel routes
395
     *
396
     * @return array
397
     */
398
    protected function customAdminCpRoutes(): array
399
    {
400
        return [
401
            'webperf' => 'webperf/sections/dashboard',
402
            'webperf/dashboard' => 'webperf/sections/dashboard',
403
            'webperf/dashboard/<siteHandle:{handle}>' => 'webperf/sections/dashboard',
404
405
            'webperf/settings' => 'webperf/settings/plugin-settings',
406
        ];
407
    }
408
409
    /**
410
     * Returns the custom Control Panel user permissions.
411
     *
412
     * @return array
413
     */
414
    protected function customAdminCpPermissions(): array
415
    {
416
        return [
417
            'webperf:dashboard' => [
418
                'label' => Craft::t('webperf', 'Dashboard'),
419
            ],
420
            'webperf:settings' => [
421
                'label' => Craft::t('webperf', 'Settings'),
422
            ],
423
        ];
424
    }
425
}
426