Passed
Push — develop ( 204b7a...d9d9af )
by Andrew
03:18
created

SectionsController::actionPagesIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 47
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 47
rs 9.44
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
46
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
47
     * @param string|null $siteHandle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
48
     * @param bool        $showWelcome
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
49
     *
50
     * @return Response
51
     * @throws NotFoundHttpException
52
     * @throws \yii\web\ForbiddenHttpException
53
     */
54
    public function actionDashboard(string $siteHandle = null, bool $showWelcome = false): Response
55
    {
56
        $variables = [];
57
        PermissionHelper::controllerPermissionCheck('webperf:dashboard');
58
        // Trim the statistics
59
        Webperf::$plugin->dataSamples->trimOrphanedSamples(1024);
60
        Webperf::$plugin->dataSamples->trimDataSamples();
61
        // Get the site to edit
62
        $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle);
63
        $pluginName = Webperf::$settings->pluginName;
64
        $templateTitle = Craft::t('webperf', 'Dashboard');
65
        $view = Craft::$app->getView();
66
        // Asset bundle
67
        try {
68
            $view->registerAssetBundle(WebperfDashboardAsset::class);
69
        } catch (InvalidConfigException $e) {
70
            Craft::error($e->getMessage(), __METHOD__);
71
        }
72
        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
73
            '@nystudio107/webperf/assetbundles/webperf/dist',
74
            true
75
        );
76
        // Enabled sites
77
        MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
78
        $variables['controllerHandle'] = 'dashboard';
79
80
        // Basic variables
81
        $variables['fullPageForm'] = false;
82
        $variables['docsUrl'] = self::DOCUMENTATION_URL;
83
        $variables['pluginName'] = $pluginName;
84
        $variables['title'] = $templateTitle;
85
        $variables['crumbs'] = [
86
            [
87
                'label' => $pluginName,
88
                'url' => UrlHelper::cpUrl('webperf'),
89
            ],
90
            [
91
                'label' => $templateTitle,
92
                'url' => UrlHelper::cpUrl('webperf/dashboard'),
93
            ],
94
        ];
95
        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
96
        $variables['selectedSubnavItem'] = 'dashboard';
97
        $variables['showWelcome'] = $showWelcome;
98
        $variables['settings'] = Webperf::$settings;
99
100
        // Render the template
101
        return $this->renderTemplate('webperf/dashboard/index', $variables);
102
    }
103
104
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
105
     * @param string|null $siteHandle
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
106
     * @param bool        $showWelcome
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Superfluous parameter comment
Loading history...
107
     *
108
     * @return Response
109
     * @throws NotFoundHttpException
110
     * @throws \yii\web\ForbiddenHttpException
111
     */
112
    public function actionPagesIndex(string $siteHandle = null): Response
113
    {
114
        $variables = [];
115
        PermissionHelper::controllerPermissionCheck('webperf:pages');
116
        // Trim the statistics
117
        Webperf::$plugin->dataSamples->trimOrphanedSamples(1024);
118
        Webperf::$plugin->dataSamples->trimDataSamples();
119
        // Get the site to edit
120
        $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle);
121
        $pluginName = Webperf::$settings->pluginName;
122
        $templateTitle = Craft::t('webperf', 'Pages');
123
        $view = Craft::$app->getView();
124
        // Asset bundle
125
        try {
126
            $view->registerAssetBundle(WebperfDashboardAsset::class);
127
        } catch (InvalidConfigException $e) {
128
            Craft::error($e->getMessage(), __METHOD__);
129
        }
130
        $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl(
131
            '@nystudio107/webperf/assetbundles/webperf/dist',
132
            true
133
        );
134
        // Enabled sites
135
        MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables);
136
        $variables['controllerHandle'] = 'dashboard';
137
138
        // Basic variables
139
        $variables['fullPageForm'] = false;
140
        $variables['docsUrl'] = self::DOCUMENTATION_URL;
141
        $variables['pluginName'] = $pluginName;
142
        $variables['title'] = $templateTitle;
143
        $variables['crumbs'] = [
144
            [
145
                'label' => $pluginName,
146
                'url' => UrlHelper::cpUrl('webperf'),
147
            ],
148
            [
149
                'label' => $templateTitle,
150
                'url' => UrlHelper::cpUrl('webperf/pages'),
151
            ],
152
        ];
153
        $variables['docTitle'] = "{$pluginName} - {$templateTitle}";
154
        $variables['selectedSubnavItem'] = 'pages';
155
        $variables['settings'] = Webperf::$settings;
156
157
        // Render the template
158
        return $this->renderTemplate('webperf/pages/index', $variables);
159
    }
160
}
161