Passed
Push — v1 ( 319b10...02d486 )
by Andrew
21:00 queued 10:28
created

Settings::behaviors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 17
rs 9.9332
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Instant Analytics plugin for Craft CMS 3.x
4
 *
5
 * Instant Analytics brings full Google Analytics support to your Twig templates
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) 2017 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\instantanalytics\models;
12
13
use nystudio107\instantanalytics\InstantAnalytics;
14
15
use craft\base\Model;
16
use craft\behaviors\EnvAttributeParserBehavior;
17
use craft\validators\ArrayValidator;
18
19
use yii\behaviors\AttributeTypecastBehavior;
20
21
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
 * @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 for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
23
 * @package   InstantAnalytics
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
24
 * @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 for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
25
 */
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...
26
class Settings extends Model
27
{
28
    // Public Properties
29
    // =========================================================================
30
31
    /**
32
     * The default Google Analytics tracking ID
33
     *
34
     * @var string
35
     */
36
    public $googleAnalyticsTracking = '';
37
38
    /**
39
     * Should the query string be stripped from the page tracking URL?
40
     *
41
     * @var bool
42
     */
43
    public $stripQueryString = true;
44
45
    /**
46
     * Should page views be sent automatically when a page view happens?
47
     *
48
     * @var bool
49
     */
50
    public $autoSendPageView = true;
51
52
    /**
53
     * The field in a Commerce Product Variant that should be used for the
54
     * category
55
     *
56
     * @var string
57
     */
58
    public $productCategoryField = '';
59
60
    /**
61
     * The field in a Commerce Product Variant that should be used for the brand
62
     *
63
     * @var string
64
     */
65
    public $productBrandField = '';
66
67
    /**
68
     * Whether add to cart events should be automatically sent
69
     *
70
     * @var bool
71
     */
72
    public $autoSendAddToCart = true;
73
74
    /**
75
     * Whether remove from cart events should be automatically sent
76
     *
77
     * @var bool
78
     */
79
    public $autoSendRemoveFromCart = true;
80
81
    /**
82
     * Whether purchase complete events should be automatically sent
83
     *
84
     * @var bool
85
     */
86
    public $autoSendPurchaseComplete = true;
87
88
    /**
89
     * Controls whether Instant Analytics will send analytics data.
90
     *
91
     * @var bool
92
     */
93
    public $sendAnalyticsData = true;
94
95
    /**
96
     * Controls whether Instant Analytics will send analytics data when
97
     * `devMode` is on.
98
     *
99
     * @var bool
100
     */
101
    public $sendAnalyticsInDevMode = true;
102
103
    /**
104
     * Controls whether we should filter out bot UserGents.
105
     *
106
     * @var bool
107
     */
108
    public $filterBotUserAgents = true;
109
110
    /**
111
     * Controls whether we should exclude users logged into an admin account
112
     * from Analytics tracking.
113
     *
114
     * @var bool
115
     */
116
    public $adminExclude = false;
117
118
    /**
119
     * Controls whether analytics that blocked from being sent should be logged
120
     * to storage/logs/web.log These are always logged if `devMode` is on
121
     *
122
     * @var bool
123
     */
124
    public $logExcludedAnalytics = true;
125
126
    /**
127
     * Contains an array of Craft user group handles to exclude from Analytics
128
     * tracking.  If there's a match for any of them, analytics data is not
129
     * sent.
130
     *
131
     * @var array
132
     */
133
    public $groupExcludes = [
134
    ];
135
136
    /**
137
     * Contains an array of keys that correspond to $_SERVER[] super-global
138
     * array keys to test against. Each item in the sub-array is tested against
139
     * the $_SERVER[] super-global key via RegEx; if there's a match for any of
140
     * them, analytics data is not sent.  This allows you to filter based on
141
     * whatever information you want. Reference:
142
     * http://php.net/manual/en/reserved.variables.server.php RegEx tester:
143
     * http://regexr.com
144
     *
145
     * @var array
146
     */
147
    public $serverExcludes = [
148
        'REMOTE_ADDR' => [
149
            '/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/',
150
        ],
151
    ];
152
153
    // Public Methods
154
    // =========================================================================
155
156
    /** @noinspection ReturnTypeCanBeDeclaredInspection */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
157
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
158
     * @return array
159
     */
160
    public function rules()
161
    {
162
        return [
163
            [
164
                [
165
                    'stripQueryString',
166
                    'autoSendPageView',
167
                    'autoSendAddToCart',
168
                    'autoSendRemoveFromCart',
169
                    'autoSendPurchaseComplete',
170
                    'sendAnalyticsData',
171
                    'sendAnalyticsInDevMode',
172
                    'filterBotUserAgents',
173
                    'adminExclude',
174
                    'logExcludedAnalytics',
175
                ],
176
                'boolean',
177
            ],
178
            [
179
                [
180
                    'googleAnalyticsTracking',
181
                    'productCategoryField',
182
                    'productBrandField',
183
                    'googleAnalyticsTracking',
184
                ],
185
                'string',
186
            ],
187
            [
188
                [
189
                    'groupExcludes',
190
                    'serverExcludes',
191
                ],
192
                ArrayValidator::class,
193
            ],
194
        ];
195
    }
196
197
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
198
     * @return array
199
     */
200
    public function behaviors()
201
    {
202
        $craft31Behaviors = [];
203
        if (InstantAnalytics::$craft31) {
204
            $craft31Behaviors = [
205
                'parser' => [
206
                    'class' => EnvAttributeParserBehavior::class,
207
                    'attributes' => [
208
                        'googleAnalyticsTracking',
209
                    ],
210
                ],
211
            ];
212
        }
213
214
        return array_merge($craft31Behaviors, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
215
            'typecast' => [
216
                'class' => AttributeTypecastBehavior::class,
217
                // 'attributeTypes' will be composed automatically according to `rules()`
218
            ],
219
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
220
    }
221
}
222