1 | <?php namespace Arcanedev\LaravelTracker; |
||
15 | class Tracker implements TrackerContract |
||
16 | { |
||
17 | /* ------------------------------------------------------------------------------------------------ |
||
18 | | Properties |
||
19 | | ------------------------------------------------------------------------------------------------ |
||
20 | */ |
||
21 | /** |
||
22 | * The application container. |
||
23 | * |
||
24 | * @var \Illuminate\Contracts\Foundation\Application |
||
25 | */ |
||
26 | protected $app; |
||
27 | |||
28 | /** |
||
29 | * The request instance. |
||
30 | * |
||
31 | * @var \Illuminate\Http\Request |
||
32 | */ |
||
33 | private $request; |
||
34 | |||
35 | /** |
||
36 | * The tracking manager. |
||
37 | * |
||
38 | * @var \Arcanedev\LaravelTracker\Contracts\TrackingManager |
||
39 | */ |
||
40 | private $trackingManager; |
||
41 | |||
42 | /** |
||
43 | * @var bool |
||
44 | */ |
||
45 | protected $enabled = false; |
||
46 | |||
47 | /** |
||
48 | * The current session data. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $sessionData = []; |
||
53 | |||
54 | /* ------------------------------------------------------------------------------------------------ |
||
55 | | Constructor |
||
56 | | ------------------------------------------------------------------------------------------------ |
||
57 | */ |
||
58 | /** |
||
59 | * Tracker constructor. |
||
60 | * |
||
61 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
62 | * @param \Arcanedev\LaravelTracker\Contracts\TrackingManager $trackingManager |
||
63 | */ |
||
64 | 24 | public function __construct(Application $app, TrackingManagerContract $trackingManager) |
|
70 | |||
71 | /* ------------------------------------------------------------------------------------------------ |
||
72 | | Getters & Setters |
||
73 | | ------------------------------------------------------------------------------------------------ |
||
74 | */ |
||
75 | /** |
||
76 | * Get the config repository. |
||
77 | * |
||
78 | * @return \Illuminate\Contracts\Config\Repository |
||
79 | */ |
||
80 | 24 | private function config() |
|
84 | |||
85 | /** |
||
86 | * Get the tracker config. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * @param mixed|null $default |
||
90 | * |
||
91 | * @return mixed |
||
92 | */ |
||
93 | 24 | private function getConfig($key, $default = null) |
|
97 | |||
98 | /** |
||
99 | * Set the request. |
||
100 | * |
||
101 | * @param \Illuminate\Http\Request $request |
||
102 | * |
||
103 | * @return self |
||
104 | */ |
||
105 | 6 | private function setRequest(Request $request) |
|
111 | |||
112 | /** |
||
113 | * Get the user agent parser. |
||
114 | * |
||
115 | * @return \Arcanedev\LaravelTracker\Contracts\Parsers\UserAgentParser |
||
116 | */ |
||
117 | 6 | public function getUserAgentParser() |
|
118 | { |
||
119 | 6 | return $this->trackingManager->getUserAgentTracker()->getUserAgentParser(); |
|
120 | } |
||
121 | |||
122 | /* ------------------------------------------------------------------------------------------------ |
||
123 | | Main Functions |
||
124 | | ------------------------------------------------------------------------------------------------ |
||
125 | */ |
||
126 | /** |
||
127 | * Start the tracking. |
||
128 | * |
||
129 | * @param \Illuminate\Http\Request $request |
||
130 | */ |
||
131 | 6 | public function track(Request $request) |
|
132 | { |
||
133 | 6 | if ($this->isEnabled()) { |
|
134 | 6 | $this->setRequest($request); |
|
135 | |||
136 | 6 | $activity = $this->getSessionActivityData(); |
|
|
|||
137 | 3 | } |
|
138 | 6 | } |
|
139 | |||
140 | /** |
||
141 | * Enable the tracker. |
||
142 | */ |
||
143 | 6 | public function enable() |
|
148 | |||
149 | /** |
||
150 | * Disable the tracker. |
||
151 | */ |
||
152 | 6 | public function disable() |
|
157 | |||
158 | /* ------------------------------------------------------------------------------------------------ |
||
159 | | Check Functions |
||
160 | | ------------------------------------------------------------------------------------------------ |
||
161 | */ |
||
162 | /** |
||
163 | * Check if the tracker is enabled. |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | 24 | public function isEnabled() |
|
171 | |||
172 | /* ------------------------------------------------------------------------------------------------ |
||
173 | | Other Functions |
||
174 | | ------------------------------------------------------------------------------------------------ |
||
175 | */ |
||
176 | /** |
||
177 | * Get the session log data. |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | 6 | protected function getSessionActivityData() |
|
195 | |||
196 | /** |
||
197 | * Get the stored session id. |
||
198 | * |
||
199 | * @return int |
||
200 | */ |
||
201 | 6 | protected function getSessionId() |
|
207 | |||
208 | /** |
||
209 | * @return array |
||
210 | */ |
||
211 | 6 | protected function makeSessionData() |
|
229 | |||
230 | /** |
||
231 | * Track the path. |
||
232 | * |
||
233 | * @return int|null |
||
234 | */ |
||
235 | 6 | private function getPathId() |
|
243 | |||
244 | 6 | private function getQueryId() |
|
248 | |||
249 | /** |
||
250 | * Get the user id. |
||
251 | * |
||
252 | * @return int|null |
||
253 | */ |
||
254 | 6 | private function getUserId() |
|
260 | |||
261 | /** |
||
262 | * Get the tracked device id. |
||
263 | * |
||
264 | * @return int|null |
||
265 | */ |
||
266 | 6 | private function getDeviceId() |
|
272 | |||
273 | /** |
||
274 | * Get the tracked ip address ip. |
||
275 | * |
||
276 | * @return int|null |
||
277 | */ |
||
278 | 6 | private function getGeoIpId() |
|
286 | |||
287 | /** |
||
288 | * Get the tracked user agent id. |
||
289 | * |
||
290 | * @return int|null |
||
291 | */ |
||
292 | 6 | private function getAgentId() |
|
298 | |||
299 | /** |
||
300 | * Get the tracked referer id. |
||
301 | * |
||
302 | * @return int|null |
||
303 | */ |
||
304 | 6 | private function getRefererId() |
|
313 | |||
314 | /** |
||
315 | * Get the tracked cookie id. |
||
316 | * |
||
317 | * @return int|null |
||
318 | */ |
||
319 | 6 | private function getCookieId() |
|
327 | |||
328 | /** |
||
329 | * Get the tracked language id. |
||
330 | * |
||
331 | * @return int|null |
||
332 | */ |
||
333 | private function getLanguageId() |
||
339 | |||
340 | /** |
||
341 | * Check if the visitor is a robot. |
||
342 | * |
||
343 | * @return bool |
||
344 | */ |
||
345 | 6 | protected function isRobot() |
|
352 | |||
353 | /** |
||
354 | * Track the trackable if enabled. |
||
355 | * |
||
356 | * @param string $key |
||
357 | * @param \Closure $callback |
||
358 | * @param mixed|null $default |
||
359 | * |
||
360 | * @return mixed |
||
361 | */ |
||
362 | 6 | private function trackIfEnabled($key, \Closure $callback, $default = null) |
|
366 | } |
||
367 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.