GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#22)
by
unknown
01:26
created

GoogleTagManager::noScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Spatie\GoogleTagManager;
4
5
use Illuminate\Support\Traits\Macroable;
6
7
class GoogleTagManager
8
{
9
    use Macroable;
10
11
    /**
12
     * @var string[]
13
     */
14
    protected $id;
15
16
    /**
17
     * @var string
18
     */
19
    protected $layer;
20
21
    /**
22
     * @var bool
23
     */
24
    protected $enabled;
25
26
    /**
27
     * @var \Spatie\GoogleTagManager\DataLayer
28
     */
29
    protected $dataLayer;
30
31
    /**
32
     * @var \Spatie\GoogleTagManager\DataLayer
33
     */
34
    protected $flashDataLayer;
35
36
    /**
37
     * @var \Spatie\GoogleTagManager\DataLayer
38
     */
39
    protected $noJSDataLayer;
40
41
    /**
42
     * @var \Illuminate\Support\Collection
43
     */
44
    protected $pushDataLayer;
45
46
    /**
47
     * @param string $id
48
     */
49
    public function __construct($id, $layer)
50
    {
51
        $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $id of type string is incompatible with the declared type array<integer,string> of property $id.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        $this->layer = $layer;
53
        $this->dataLayer = new DataLayer();
54
        $this->flashDataLayer = new DataLayer();
55
        $this->noJSDataLayer = new DataLayer();
56
        $this->pushDataLayer = new \Illuminate\Support\Collection();
57
58
        $this->enabled = true;
59
    }
60
61
    /**
62
     * Return the Google Tag Manager id.
63
     *
64
     * @return string[]
65
     */
66
    public function id()
67
    {
68
        return $this->id;
69
    }
70
71
    /**
72
     * Return the Google Tag Manager id.
73
     *
74
     * @return string
75
     */
76
    public function getLayer()
77
    {
78
        return $this->layer;
79
    }
80
81
    /**
82
     * Check whether script rendering is enabled.
83
     *
84
     * @return bool
85
     */
86
    public function isEnabled()
87
    {
88
        return $this->enabled;
89
    }
90
91
    /**
92
     * Enable Google Tag Manager scripts rendering.
93
     */
94
    public function enable()
95
    {
96
        $this->enabled = true;
97
    }
98
99
    /**
100
     * Disable Google Tag Manager scripts rendering.
101
     */
102
    public function disable()
103
    {
104
        $this->enabled = false;
105
    }
106
107
    /**
108
     * Add data to the data layer.
109
     *
110
     * @param array|string $key
111
     * @param mixed        $value
112
     */
113
    public function set($key, $value = null)
114
    {
115
        $this->dataLayer->set($key, $value);
116
    }
117
118
    /**
119
     * Retrieve the data layer.
120
     *
121
     * @return \Spatie\GoogleTagManager\DataLayer
122
     */
123
    public function getDataLayer()
124
    {
125
        return $this->dataLayer;
126
    }
127
128
    /**
129
     * Add data to the data layer for the next request.
130
     *
131
     * @param array|string $key
132
     * @param mixed        $value
133
     */
134
    public function flash($key, $value = null)
135
    {
136
        $this->flashDataLayer->set($key, $value);
137
    }
138
139
    /**
140
     * Retrieve the data layer's data for the next request.
141
     *
142
     * @return array
143
     */
144
    public function getFlashData()
145
    {
146
        return $this->flashDataLayer->toArray();
147
    }
148
149
    /**
150
     * Add data to the data layer for the next request.
151
     *
152
     * @param array|string $key
153
     * @param mixed        $value
154
     */
155
    public function noScript($key, $value = null)
156
    {
157
        $this->noJSDataLayer->set($key, $value);
158
    }
159
160
    /**
161
     * Retrieve the data layer's data for the next request.
162
     *
163
     * @return array
164
     */
165
    public function getNoScriptData()
166
    {
167
        return $this->noJSDataLayer->toArray();
168
    }
169
170
    /**
171
     * Add data to be pushed to the data layer.
172
     *
173
     * @param array|string $key
174
     * @param mixed        $value
175
     */
176
    public function push($key, $value = null)
177
    {
178
        $pushItem = new DataLayer();
179
        $pushItem->set($key, $value);
180
        $this->pushDataLayer->push($pushItem);
181
    }
182
183
    /**
184
     * Retrieve the data layer's data for the next request.
185
     *
186
     * @return \Illuminate\Support\Collection
187
     */
188
    public function getPushData()
189
    {
190
        return $this->pushDataLayer;
191
    }
192
193
    /**
194
     * Clear the data layer.
195
     */
196
    public function clear()
197
    {
198
        $this->dataLayer = new DataLayer();
199
        $this->pushDataLayer = new \Illuminate\Support\Collection();
200
    }
201
202
    /**
203
     * Utility function to dump an array as json.
204
     *
205
     * @param  array $data
206
     * @return string
207
     */
208
    public function dump($data)
209
    {
210
        return (new DataLayer($data))->toJson();
211
    }
212
}
213