Passed
Push — v1 ( 65d641...7780c4 )
by Andrew
02:59
created

DataSample::fields()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
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) 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\models;
12
13
use nystudio107\webperf\validators\DbStringValidator;
14
15
use yii\behaviors\AttributeTypecastBehavior;
0 ignored issues
show
Bug introduced by
The type yii\behaviors\AttributeTypecastBehavior 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
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
 * @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...
19
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
20
 * @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...
21
 */
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...
22
class DataSample extends DbModel
23
{
24
    // Constants
25
    // =========================================================================
26
27
    const SCENARIO_BOOMERANG_BEACON = 'boomerang-beacon';
28
    const SCENARIO_CRAFT_BEACON = 'craft-beacon';
29
    const BOOMERANG_BEACON_FIELDS = [
30
        'requestId',
31
        'siteId',
32
        'title',
33
        'url',
34
        'dns',
35
        'connect',
36
        'firstByte',
37
        'firstPaint',
38
        'firstContentfulPaint',
39
        'domInteractive',
40
        'pageLoad',
41
        'countryCode',
42
        'device',
43
        'browser',
44
        'os',
45
        'mobile',
46
    ];
47
    const CRAFT_BEACON_FIELDS = [
48
        'requestId',
49
        'url',
50
        'craftTotalMs',
51
        'craftDbMs',
52
        'craftDbCnt',
53
        'craftTwigMs',
54
        'craftTwigCnt',
55
        'craftOtherMs',
56
        'craftOtherCnt',
57
        'craftTotalMemory',
58
    ];
59
    const PLACEHOLDER_URL = 'webperf-craft-placeholder';
60
61
    // Public Properties
62
    // =========================================================================
63
64
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
65
     * @var int
66
     */
67
    public $requestId;
68
69
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @var int
71
     */
72
    public $siteId;
73
74
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
75
     * @var string the title of the document (if any)
76
     */
77
    public $title;
78
79
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
80
     * @var string u - the URL of the User Timing sample
81
     */
82
    public $url;
83
84
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
85
     * @var int (nt_dns_end - nt_dns_st) in ms
86
     */
87
    public $dns;
88
89
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
90
     * @var int (nt_con_end - nt_con_st) in ms
91
     */
92
    public $connect;
93
94
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
95
     * @var int t_resp in ms
96
     */
97
    public $firstByte;
98
99
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
100
     * @var int pt_fp in ms
101
     */
102
    public $firstPaint;
103
104
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
105
     * @var int pt_fcp in ms
106
     */
107
    public $firstContentfulPaint;
108
109
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
110
     * @var int (nt_domint - nt_nav_st) in ms
111
     */
112
    public $domInteractive;
113
114
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
115
     * @var int (nt_domcomp - nt_nav_st) or t_done in ms
116
     */
117
    public $pageLoad;
118
119
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
120
     * @var string the country code from the IP address
121
     */
122
    public $countryCode;
123
124
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
125
     * @var string the device name
126
     */
127
    public $device;
128
129
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
130
     * @var string the browser name
131
     */
132
    public $browser;
133
134
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
135
     * @var string the operating system
136
     */
137
    public $os;
138
139
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
140
     * @var bool mobile or non-mobile
141
     */
142
    public $mobile;
143
144
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
145
     * @var int
146
     */
147
    public $craftTotalMs;
148
149
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
150
     * @var int
151
     */
152
    public $craftDbMs;
153
154
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
155
     * @var int
156
     */
157
    public $craftDbCnt;
158
159
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
160
     * @var int
161
     */
162
    public $craftTwigMs;
163
164
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
165
     * @var int
166
     */
167
    public $craftTwigCnt;
168
169
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
170
     * @var int
171
     */
172
    public $craftOtherMs;
173
174
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
175
     * @var int
176
     */
177
    public $craftOtherCnt;
178
179
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
180
     * @var int
181
     */
182
    public $craftTotalMemory;
183
184
    // Public Methods
185
    // =========================================================================
186
187
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
188
     * @inheritdoc
189
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
190
    public function rules()
191
    {
192
        return [
193
            ['requestId', 'integer'],
194
            ['siteId', 'integer'],
195
            ['url', 'required'],
196
            ['title', DbStringValidator::class, 'max' => 120],
197
            ['url', DbStringValidator::class, 'max' => 255],
198
            ['countryCode', DbStringValidator::class, 'max' => 2],
199
            ['device', DbStringValidator::class, 'max' => 50],
200
            ['browser', DbStringValidator::class, 'max' => 50],
201
            ['os', DbStringValidator::class, 'max' => 50],
202
            [
203
                [
204
                    'title',
205
                    'url',
206
                    'countryCode',
207
                    'device',
208
                    'browser',
209
                    'os',
210
                ],
211
                'string'
212
            ],
213
            [
214
                [
215
                    'dns',
216
                    'connect',
217
                    'firstByte',
218
                    'firstPaint',
219
                    'firstContentfulPaint',
220
                    'domInteractive',
221
                    'pageLoad',
222
                    'craftTotalMs',
223
                    'craftDbMs',
224
                    'craftDbCnt',
225
                    'craftTwigMs',
226
                    'craftTwigCnt',
227
                    'craftOtherMs',
228
                    'craftOtherCnt',
229
                    'craftTotalMemory',
230
                ],
231
                'integer'
232
            ],
233
            ['mobile', 'boolean'],
234
        ];
235
    }
236
237
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
238
     * @inheritdoc
239
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
240
    public function fields()
241
    {
242
        $fields = parent::fields();
243
        switch ($this->scenario) {
244
            case self::SCENARIO_BOOMERANG_BEACON:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
245
                $fields = self::BOOMERANG_BEACON_FIELDS;
246
                break;
247
            case self::SCENARIO_CRAFT_BEACON:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
248
                $fields = self::CRAFT_BEACON_FIELDS;
249
                break;
250
        }
251
252
        return $fields;
253
    }
254
255
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
256
     * @inheritdoc
257
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
258
    public function scenarios()
259
    {
260
        return [
261
            self::SCENARIO_BOOMERANG_BEACON => self::BOOMERANG_BEACON_FIELDS,
262
            self::SCENARIO_CRAFT_BEACON => self::CRAFT_BEACON_FIELDS,
263
        ];
264
    }
265
266
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
267
     * @return array
268
     */
269
    public function behaviors()
270
    {
271
        return [
272
            'typecast' => [
273
                'class' => AttributeTypecastBehavior::class,
274
                // 'attributeTypes' will be composed automatically according to `rules()`
275
            ],
276
        ];
277
    }
278
}
279