Passed
Push — develop ( 71abba...d7f64b )
by Andrew
09:10
created

SectionsController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 32
dl 0
loc 68
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionDashboard() 0 46 2
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\controllers;
12
13
use nystudio107\webperf\Webperf;
14
use nystudio107\webperf\assetbundles\webperf\WebperfDashboardAsset;
15
use nystudio107\webperf\helpers\MultiSite as MultiSiteHelper;
16
use nystudio107\webperf\helpers\Permission as PermissionHelper;
17
18
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...
19
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...
20
use craft\web\Controller;
0 ignored issues
show
Bug introduced by
The type craft\web\Controller 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
22
use yii\base\InvalidConfigException;
0 ignored issues
show
Bug introduced by
The type yii\base\InvalidConfigException 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 yii\web\NotFoundHttpException;
0 ignored issues
show
Bug introduced by
The type yii\web\NotFoundHttpException 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 yii\web\Response;
0 ignored issues
show
Bug introduced by
The type yii\web\Response 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
26
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
27
 * @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...
28
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
29
 * @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...
30
 */
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...
31
class SectionsController extends Controller
32
{
33
    // Constants
34
    // =========================================================================
35
36
    const DOCUMENTATION_URL = 'https://github.com/nystudio107/craft-webperf/';
37
38
    // Protected Properties
39
    // =========================================================================
40
41
    protected $allowAnonymous = [];
42
43
    // Public Methods
44
    // =========================================================================
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @param string|null $siteHandle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
47
     * @param bool        $showWelcome
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
48
     *
49
     * @return Response
50
     * @throws NotFoundHttpException
51
     * @throws \yii\web\ForbiddenHttpException
52
     */
53
    public function actionDashboard(string $siteHandle = null, bool $showWelcome = false): Response
54
    {
55
        $variables = [];
56
        PermissionHelper::controllerPermissionCheck('webperf:dashboard');
57
        // Trim the statistics
58
        Webperf::$plugin->dataSamples->trimDataSamples();
59
        // Get the site to edit
60
        $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle);
61
        $pluginName = Webperf::$settings->pluginName;
62
        $templateTitle = Craft::t('webperf', 'Dashboard');
63
        $view = Craft::$app->getView();
64
        // Asset bundle
65
        try {
66
            $view->registerAssetBundle(WebperfDashboardAsset::class);
67
        } catch (InvalidConfigException $e) {
68
            Craft::error($e->getMessage(), __METHOD__);
69
        }
70
        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
71
            '@nystudio107/webperf/assetbundles/webperf/dist',
72
            true
73
        );
74
        // Enabled sites
75
        MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
76
        $variables['controllerHandle'] = 'dashboard';
77
78
        // Basic variables
79
        $variables['fullPageForm'] = false;
80
        $variables['docsUrl'] = self::DOCUMENTATION_URL;
81
        $variables['pluginName'] = $pluginName;
82
        $variables['title'] = $templateTitle;
83
        $variables['crumbs'] = [
84
            [
85
                'label' => $pluginName,
86
                'url' => UrlHelper::cpUrl('webperf'),
87
            ],
88
            [
89
                'label' => $templateTitle,
90
                'url' => UrlHelper::cpUrl('webperf/dashboard'),
91
            ],
92
        ];
93
        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
94
        $variables['selectedSubnavItem'] = 'dashboard';
95
        $variables['showWelcome'] = $showWelcome;
96
97
        // Render the template
98
        return $this->renderTemplate('webperf/dashboard/index', $variables);
99
    }
100
}
101