Passed
Push — v1 ( fa91c5...11499b )
by Andrew
08:22 queued 05:22
created

Settings::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 19
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
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) 2019 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\models;
12
13
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...
14
use craft\base\Model;
0 ignored issues
show
Bug introduced by
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
Bug introduced by
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
Bug introduced by
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
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @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...
21
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
22
 * @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...
23
 */
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...
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
Coding Style introduced by
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
Coding Style introduced by
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
Coding Style introduced by
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
Coding Style introduced by
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
Coding Style introduced by
Missing short description in doc comment
Loading history...
55
     * @var int The number of data samples to store
56
     */
57
    public $dataSamplesStoredLimit = 10000;
58
59
    /**
0 ignored issues
show
Coding Style introduced by
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
Coding Style introduced by
Missing short description in doc comment
Loading history...
65
     * @var int The number of milliseconds required between recording of frontend beacon data samples
66
     */
67
    public $rateLimitMs = 500;
68
69
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @var string API Key for WebPageTest.org
71
     */
72
    public $webpageTestApiKey = '';
73
74
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
75
     * @var bool Whether to filter bot user agents from generating profile hits or not
76
     *           NOT visible in the GUI currently
77
     */
78
    public $filterBotUserAgents = true;
79
80
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
81
     * @var string The dashboard 'fast' color for charts
82
     */
83
    public $dashboardFastColor = '#00C800';
84
85
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
     * @var string The dashboard 'average' color for charts
87
     */
88
    public $dashboardAverageColor = '#FFFF00';
89
90
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
91
     * @var string The dashboard 'slow' color for charts
92
     */
93
    public $dashboardSlowColor = '#C80000';
94
95
    // Public Methods
96
    // =========================================================================
97
98
    public function init()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
99
    {
100
        parent::init();
101
        // If Blitz is installed & enabled, flip the $staticCachedSite on
102
        $blitz = Craft::$app->getPlugins()->getPlugin(self::BLITZ_PLUGIN_HANDLE);
103
        if ($blitz && Blitz::$plugin->getSettings()->cachingEnabled) {
104
            $this->staticCachedSite = true;
105
        }
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 rules()
112
    {
113
        return [
114
            ['pluginName', 'string'],
115
            ['pluginName', 'default', 'value' => 'Webperf'],
116
            ['includeBeacon', 'boolean'],
117
            ['includeCraftProfiling', 'boolean'],
118
            ['staticCachedSite', 'boolean'],
119
            ['dataSamplesStoredLimit', 'integer'],
120
            ['dataSamplesStoredLimit', 'default', 'value' => 10000],
121
            ['automaticallyTrimDataSamples', 'boolean'],
122
            ['rateLimitMs', 'integer'],
123
            ['rateLimitMs', 'default', 'value' => 500],
124
            ['webpageTestApiKey', 'string'],
125
            ['filterBotUserAgents', 'boolean'],
126
            ['dashboardFastColor', 'default', 'value' => '#00C800'],
127
            ['dashboardAverageColor', 'default', 'value' => '#FFFF00'],
128
            ['dashboardSlowColor', 'default', 'value' => '#C80000'],
129
            [['dashboardFastColor', 'dashboardAverageColor', 'dashboardSlowColor'], ColorValidator::class],
130
        ];
131
    }
132
}
133