Passed
Push — develop ( d5b015...010630 )
by Andrew
08:25
created

Settings::behaviors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
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 category
54
     *
55
     * @var string
56
     */
57
    public $productCategoryField = '';
58
59
    /**
60
     * The field in a Commerce Product Variant that should be used for the brand
61
     *
62
     * @var string
63
     */
64
    public $productBrandField = '';
65
66
    /**
67
     * Whether add to cart events should be automatically sent
68
     *
69
     * @var bool
70
     */
71
    public $autoSendAddToCart = true;
72
73
    /**
74
     * Whether remove from cart events should be automatically sent
75
     *
76
     * @var bool
77
     */
78
    public $autoSendRemoveFromCart = true;
79
80
    /**
81
     * Whether purchase complete events should be automatically sent
82
     *
83
     * @var bool
84
     */
85
    public $autoSendPurchaseComplete = true;
86
87
    /**
88
     * Controls whether Instant Analytics will send analytics data.
89
     *
90
     * @var bool
91
     */
92
    public $sendAnalyticsData = true;
93
94
    /**
95
     * Controls whether Instant Analytics will send analytics data when
96
     * `devMode` is on.
97
     *
98
     * @var bool
99
     */
100
    public $sendAnalyticsInDevMode = true;
101
102
    /**
103
     * Controls whether we should filter out bot UserGents.
104
     *
105
     * @var bool
106
     */
107
    public $filterBotUserAgents = true;
108
109
    /**
110
     * Controls whether we should exclude users logged into an admin account
111
     * from Analytics tracking.
112
     *
113
     * @var bool
114
     */
115
    public $adminExclude = false;
116
117
    /**
118
     * Controls whether analytics that blocked from being sent should be logged
119
     * to storage/logs/web.log These are always logged if `devMode` is on
120
     *
121
     * @var bool
122
     */
123
    public $logExcludedAnalytics = true;
124
125
    /**
126
     * Contains an array of Craft user group handles to exclude from Analytics
127
     * tracking.  If there's a match for any of them, analytics data is not
128
     * sent.
129
     *
130
     * @var array
131
     */
132
    public $groupExcludes = [
133
    ];
134
135
    /**
136
     * Contains an array of keys that correspond to $_SERVER[] super-global
137
     * array keys to test against. Each item in the sub-array is tested against
138
     * the $_SERVER[] super-global key via RegEx; if there's a match for any of
139
     * them, analytics data is not sent.  This allows you to filter based on
140
     * whatever information you want. Reference:
141
     * http://php.net/manual/en/reserved.variables.server.php RegEx tester:
142
     * http://regexr.com
143
     *
144
     * @var array
145
     */
146
    public $serverExcludes = [
147
        'REMOTE_ADDR' => [
148
            '/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/',
149
        ],
150
    ];
151
152
    // Public Methods
153
    // =========================================================================
154
155
    /** @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...
156
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
157
     * @return array
158
     */
159
    public function rules()
160
    {
161
        return [
162
            [
163
                [
164
                    'stripQueryString',
165
                    'autoSendPageView',
166
                    'autoSendAddToCart',
167
                    'autoSendRemoveFromCart',
168
                    'autoSendPurchaseComplete',
169
                    'sendAnalyticsData',
170
                    'sendAnalyticsInDevMode',
171
                    'filterBotUserAgents',
172
                    'adminExclude',
173
                    'logExcludedAnalytics',
174
                ],
175
                'boolean'
176
            ],
177
            [
178
                [
179
                    'googleAnalyticsTracking',
180
                    'productCategoryField',
181
                    'productBrandField',
182
                    'googleAnalyticsTracking',
183
                ],
184
                'string'
185
            ],
186
            [
187
                [
188
                    'groupExcludes',
189
                    'serverExcludes',
190
                ],
191
                ArrayValidator::class
192
            ],
193
        ];
194
    }
195
196
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
197
     * @return array
198
     */
199
    public function behaviors()
200
    {
201
        $craft31Behaviors = [];
202
        if (InstantAnalytics::$craft31) {
203
            $craft31Behaviors = [
204
                'parser' => [
205
                    'class' => EnvAttributeParserBehavior::class,
206
                    'attributes' => [
207
                        'googleAnalyticsTracking',
208
                    ],
209
                ]
210
            ];
211
        }
212
213
        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...
214
            'typecast' => [
215
                'class' => AttributeTypecastBehavior::class,
216
                // 'attributeTypes' will be composed automatically according to `rules()`
217
            ],
218
        ]);
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...
219
    }
220
}
221