Passed
Push — v1 ( 63c526...da15fc )
by Andrew
08:26 queued 05:04
created

src/models/Settings.php (41 issues)

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
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2019 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\webperf\models;
12
13
use Craft;
0 ignored issues
show
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...
14
use craft\base\Model;
0 ignored issues
show
The type craft\base\Model 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...
15
use craft\validators\ColorValidator;
0 ignored issues
show
The type craft\validators\ColorValidator 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...
16
17
use putyourlightson\blitz\Blitz;
0 ignored issues
show
The type putyourlightson\blitz\Blitz 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...
18
19
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
20
 * @author    nystudio107
0 ignored issues
show
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value indented incorrectly; expected 2 spaces but found 4
Loading history...
21
 * @package   Webperf
0 ignored issues
show
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
22
 * @since     1.0.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value indented incorrectly; expected 3 spaces but found 5
Loading history...
23
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
24
class Settings extends Model
25
{
26
    // Constants
27
    // =========================================================================
28
29
    const BLITZ_PLUGIN_HANDLE = 'blitz';
30
31
    // Public Properties
32
    // =========================================================================
33
34
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
35
     * @var string The public-facing name of the plugin
36
     */
37
    public $pluginName = 'Webperf';
38
39
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
40
     * @var bool Whether or not to include the beacon on the page
41
     */
42
    public $includeBeacon = true;
43
44
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
45
     * @var bool Whether or not to include the Craft profiling of pages
46
     */
47
    public $includeCraftProfiling = true;
48
49
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
50
     * @var bool If the site is static cached, turn this option on to prevent Webperf from generating a unique beacon token
51
     */
52
    public $staticCachedSite = false;
53
54
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
55
     * @var int The number of data samples to store
56
     */
57
    public $dataSamplesStoredLimit = 100000;
58
59
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
60
     * @var bool Whether the DataSamples should be trimmed after each new DataSample is added
61
     */
62
    public $automaticallyTrimDataSamples = true;
63
64
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
65
     * @var bool Whether outlier data samples that are 10x the mean should be deleted
66
     */
67
    public $trimOutlierDataSamples = true;
68
69
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
70
     * @var int The number of milliseconds required between recording of frontend beacon data samples
71
     */
72
    public $rateLimitMs = 500;
73
74
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
75
     * @var string API Key for WebPageTest.org
76
     */
77
    public $webpageTestApiKey = '';
78
79
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
80
     * @var bool Whether Craft `warning` messages should be recorded in addition to `error` messages
81
     */
82
    public $includeCraftWarnings = false;
83
84
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
85
     * @var int The number of error samples to store
86
     */
87
    public $errorSamplesStoredLimit = 1000;
88
89
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
90
     * @var bool Whether the ErrorSamples should be trimmed after each new ErrorSample is added
91
     */
92
    public $automaticallyTrimErrorSamples = true;
93
94
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
95
     * @var bool Whether to filter bot user agents from generating profile hits or not
96
     *           NOT visible in the GUI currently
97
     */
98
    public $filterBotUserAgents = true;
99
100
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
101
     * @var bool Whether the performance summary sidebar should be shown on entry, category, and product pages
102
     */
103
    public $displaySidebar = true;
104
105
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
106
     * @var string The dashboard 'fast' color for charts
107
     */
108
    public $dashboardFastColor = '#00C800';
109
110
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
111
     * @var string The dashboard 'average' color for charts
112
     */
113
    public $dashboardAverageColor = '#FFFF00';
114
115
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
116
     * @var string The dashboard 'slow' color for charts
117
     */
118
    public $dashboardSlowColor = '#C80000';
119
120
    // Public Methods
121
    // =========================================================================
122
123
    public function init()
0 ignored issues
show
You must use "/**" style comments for a function comment
Loading history...
124
    {
125
        parent::init();
126
        // If Blitz is installed & enabled, flip the $staticCachedSite on
127
        $blitz = Craft::$app->getPlugins()->getPlugin(self::BLITZ_PLUGIN_HANDLE);
128
        if ($blitz && Blitz::$plugin->getSettings()->cachingEnabled) {
129
            $this->staticCachedSite = true;
130
        }
131
    }
132
133
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
134
     * @inheritdoc
135
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
136
    public function rules()
137
    {
138
        return [
139
            ['pluginName', 'string'],
140
            ['pluginName', 'default', 'value' => 'Webperf'],
141
            ['includeBeacon', 'boolean'],
142
            ['includeCraftProfiling', 'boolean'],
143
            ['staticCachedSite', 'boolean'],
144
            ['dataSamplesStoredLimit', 'integer'],
145
            ['dataSamplesStoredLimit', 'default', 'value' => 100000],
146
            ['automaticallyTrimDataSamples', 'boolean'],
147
            ['trimOutlierDataSamples', 'boolean'],
148
            ['rateLimitMs', 'integer'],
149
            ['rateLimitMs', 'default', 'value' => 500],
150
            ['webpageTestApiKey', 'string'],
151
            ['includeCraftWarnings', 'boolean'],
152
            ['errorSamplesStoredLimit', 'integer'],
153
            ['errorSamplesStoredLimit', 'default', 'value' => 1000],
154
            ['automaticallyTrimErrorSamples', 'boolean'],
155
            ['filterBotUserAgents', 'boolean'],
156
            ['displaySidebar', 'boolean'],
157
            ['dashboardFastColor', 'default', 'value' => '#00C800'],
158
            ['dashboardAverageColor', 'default', 'value' => '#FFA500'],
159
            ['dashboardSlowColor', 'default', 'value' => '#C80000'],
160
            [
161
                [
162
                    'dashboardFastColor',
163
                    'dashboardAverageColor',
164
                    'dashboardSlowColor',
165
                ],
166
                ColorValidator::class
167
            ],
168
        ];
169
    }
170
}
171