Issues (587)

src/helpers/IAnalytics.php (41 issues)

1
<?php
2
/**
3
 * Instant Analytics plugin for Craft CMS
4
 *
5
 * @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...
6
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
The tag in position 2 should be the @author tag
Loading history...
@copyright tag must contain a year and the name of the copyright holder
Loading history...
7
 * @link      http://nystudio107.com
0 ignored issues
show
The tag in position 3 should be the @copyright tag
Loading history...
8
 * @package   InstantAnalytics
0 ignored issues
show
The tag in position 4 should be the @link tag
Loading history...
9
 * @since     1.0.0
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\instantanalytics\helpers;
13
14
use nystudio107\instantanalytics\InstantAnalytics;
15
use nystudio107\instantanalytics\models\Settings;
16
17
use Craft;
18
19
use \TheIconic\Tracking\GoogleAnalytics\Analytics;
0 ignored issues
show
The type \TheIconic\Tracking\GoogleAnalytics\Analytics 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...
20
use \TheIconic\Tracking\GoogleAnalytics\AnalyticsResponseInterface;
0 ignored issues
show
The type \TheIconic\Tracking\Goog...lyticsResponseInterface 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...
21
22
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
23
 * @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 for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
24
 * @package   InstantAnalytics
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
25
 * @since     1.0.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
26
 */
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...
27
class IAnalytics extends Analytics
28
{
29
30
    protected $shouldSendAnalytics = null;
31
32
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $isSsl should have a doc-comment as per coding-style.
Loading history...
Parameter $isDisabled should have a doc-comment as per coding-style.
Loading history...
Parameter $options should have a doc-comment as per coding-style.
Loading history...
33
     * @inheritdoc
34
     */
35
    public function __construct($isSsl = false, $isDisabled = false, array $options = [])
36
    {
37
        // Store whether or not we should be sending Analytics data
38
        $this->shouldSendAnalytics = InstantAnalytics::$settings->sendAnalyticsData;
39
40
        parent::__construct($isSsl, $isDisabled, $options);
41
    }
42
43
    /**
44
     * Turn an empty value so the twig tags {{ }} can be used
45
     *
46
     * @return string ''
47
     */
48
    public function __toString()
49
    {
50
        return '';
51
    }
52
53
    /**
54
     * Add a product impression to the Analytics object
55
     *
56
     * @param string $productVariant
0 ignored issues
show
Missing parameter comment
Loading history...
57
     * @param int    $index
0 ignored issues
show
Missing parameter comment
Loading history...
58
     * @param string $listName
0 ignored issues
show
Missing parameter comment
Loading history...
59
     * @param int    $listIndex
0 ignored issues
show
Missing parameter comment
Loading history...
60
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
61
    public function addCommerceProductImpression(
62
        $productVariant = null,
63
        $index = 0,
64
        $listName = 'default',
65
        $listIndex = 1
66
    ) {
67
68
        if (InstantAnalytics::$commercePlugin) {
69
            if ($productVariant) {
70
                InstantAnalytics::$plugin->commerce->addCommerceProductImpression(
71
                    $this,
72
                    $productVariant,
0 ignored issues
show
$productVariant of type string is incompatible with the type craft\commerce\elements\...mmerce\elements\Variant expected by parameter $productVariant of nystudio107\instantanaly...erceProductImpression(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
                    /** @scrutinizer ignore-type */ $productVariant,
Loading history...
73
                    $index,
74
                    $listName,
75
                    $listIndex
76
                );
77
            }
78
        } else {
79
            Craft::warning(
80
                Craft::t(
81
                    'instant-analytics',
82
                    'Craft Commerce is not installed'
83
                ),
84
                __METHOD__
85
            );
86
        }
87
    }
88
89
    /**
90
     * Add a product detail view to the Analytics object
91
     *
92
     * @param string $productVariant
0 ignored issues
show
Missing parameter comment
Loading history...
93
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
94
    public function addCommerceProductDetailView($productVariant = null)
95
    {
96
        if (InstantAnalytics::$commercePlugin) {
97
            if ($productVariant) {
98
                InstantAnalytics::$plugin->commerce->addCommerceProductDetailView($this, $productVariant);
0 ignored issues
show
$productVariant of type string is incompatible with the type craft\commerce\elements\...mmerce\elements\Variant expected by parameter $productVariant of nystudio107\instantanaly...erceProductDetailView(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

98
                InstantAnalytics::$plugin->commerce->addCommerceProductDetailView($this, /** @scrutinizer ignore-type */ $productVariant);
Loading history...
99
            }
100
        } else {
101
            Craft::warning(
102
                Craft::t(
103
                    'instant-analytics',
104
                    'Craft Commerce is not installed'
105
                ),
106
                __METHOD__
107
            );
108
        }
109
    }
110
111
    /**
112
     * Add a checkout step to the Analytics object
113
     *
114
     * @param        $orderModel
0 ignored issues
show
Tag value for @param tag indented incorrectly; expected 1 spaces but found 8
Loading history...
Missing parameter comment
Loading history...
115
     * @param int    $step
0 ignored issues
show
Missing parameter comment
Loading history...
116
     * @param string $option
0 ignored issues
show
Missing parameter comment
Loading history...
117
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
118
    public function addCommerceCheckoutStep($orderModel = null, $step = 1, $option = "")
119
    {
120
        if (InstantAnalytics::$commercePlugin) {
121
            if ($orderModel) {
122
                InstantAnalytics::$plugin->commerce->addCommerceCheckoutStep($this, $orderModel, $step, $option);
123
            }
124
        } else {
125
            Craft::warning(
126
                Craft::t(
127
                    'instant-analytics',
128
                    'Craft Commerce is not installed'
129
                ),
130
                __METHOD__
131
            );
132
        }
133
    }
134
135
    /**
136
     * Override sendHit() so that we can prevent Analytics data from being sent
137
     *
138
     * @param $methodName
0 ignored issues
show
Missing parameter comment
Loading history...
139
     *
140
     * @return AnalyticsResponseInterface|null
141
     */
142
    protected function sendHit($methodName)
143
    {
144
        $requestIp = $_SERVER['REMOTE_ADDR'];
145
        if ($this->shouldSendAnalytics) {
146
            if ($this->getClientId() !== null || $this->getUserId() !== null) {
147
                try {
148
                    Craft::info(
149
                        'Send hit for IAnalytics object: ' . print_r($this, true),
0 ignored issues
show
Are you sure print_r($this, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

149
                        'Send hit for IAnalytics object: ' . /** @scrutinizer ignore-type */ print_r($this, true),
Loading history...
150
                        __METHOD__
151
                    );
152
153
                    return parent::sendHit($methodName);
154
                } catch (\Exception $e) {
155
                    if (InstantAnalytics::$settings->logExcludedAnalytics) {
156
                        Craft::info(
157
                            '*** sendHit(): error sending analytics: ' . $e->getMessage(),
158
                            __METHOD__
159
                        );
160
                    }
161
                }
162
            } elseif (InstantAnalytics::$settings->logExcludedAnalytics) {
163
                Craft::info(
164
                    '*** sendHit(): analytics not sent for '.$requestIp. ' because no clientId or userId is set',
165
                    __METHOD__
166
                );
167
            }
168
        } elseif (InstantAnalytics::$settings->logExcludedAnalytics) {
169
            Craft::info(
170
                '*** sendHit(): analytics not sent for '.$requestIp,
171
                __METHOD__
172
            );
173
        }
174
175
        return null;
176
    }
177
}
178