1 | <?php namespace Arcanedev\LaravelTracker; |
||
15 | class Tracker implements TrackerContract |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Traits |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | use Traits\TrackersMaker; |
||
23 | |||
24 | /* ----------------------------------------------------------------- |
||
25 | | Properties |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * The application container. |
||
31 | * |
||
32 | * @var \Illuminate\Contracts\Foundation\Application |
||
33 | */ |
||
34 | protected $app; |
||
35 | |||
36 | /** |
||
37 | * The request instance. |
||
38 | * |
||
39 | * @var \Illuminate\Http\Request |
||
40 | */ |
||
41 | private $request; |
||
42 | |||
43 | /** |
||
44 | * Tracking enabled status. |
||
45 | * |
||
46 | * @var bool |
||
47 | */ |
||
48 | protected $enabled = false; |
||
49 | |||
50 | /** |
||
51 | * The current visitor data. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $visitorData = [ |
||
56 | 'user_id' => null, |
||
57 | 'device_id' => null, |
||
58 | 'agent_id' => null, |
||
59 | 'geoip_id' => null, |
||
60 | 'referer_id' => null, |
||
61 | 'cookie_id' => null, |
||
62 | 'language_id' => null, |
||
63 | 'client_ip' => '', |
||
64 | 'is_robot' => false, |
||
65 | 'user_agent' => '', |
||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * The current visitor activity data. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $visitorActivityData = [ |
||
74 | 'visitor_id' => null, |
||
75 | 'path_id' => null, |
||
76 | 'query_id' => null, |
||
77 | 'referer_id' => null, |
||
78 | 'route_path_id' => null, |
||
79 | 'error_id' => null, |
||
80 | 'method' => '', |
||
81 | 'is_ajax' => false, |
||
82 | 'is_secure' => false, |
||
83 | 'is_json' => false, |
||
84 | 'wants_json' => false, |
||
85 | ]; |
||
86 | |||
87 | /** |
||
88 | * Indicates if migrations will be run. |
||
89 | * |
||
90 | * @var bool |
||
91 | */ |
||
92 | public static $runsMigrations = true; |
||
93 | |||
94 | /* ----------------------------------------------------------------- |
||
95 | | Constructor |
||
96 | | ----------------------------------------------------------------- |
||
97 | */ |
||
98 | |||
99 | /** |
||
100 | * Tracker constructor. |
||
101 | * |
||
102 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
103 | */ |
||
104 | 117 | public function __construct(Application $app) |
|
109 | |||
110 | /* ----------------------------------------------------------------- |
||
111 | | Getters & Setters |
||
112 | | ----------------------------------------------------------------- |
||
113 | */ |
||
114 | |||
115 | /** |
||
116 | * Get the application instance. |
||
117 | * |
||
118 | * @return \Illuminate\Contracts\Foundation\Application |
||
119 | */ |
||
120 | 117 | protected function app() |
|
124 | |||
125 | /** |
||
126 | * Get the config repository. |
||
127 | * |
||
128 | * @return \Illuminate\Contracts\Config\Repository |
||
129 | */ |
||
130 | 117 | private function config() |
|
134 | |||
135 | /** |
||
136 | * Get the tracker config. |
||
137 | * |
||
138 | * @param string $key |
||
139 | * @param mixed|null $default |
||
140 | * |
||
141 | * @return mixed |
||
142 | */ |
||
143 | 117 | private function getConfig($key, $default = null) |
|
147 | |||
148 | /** |
||
149 | * Set the request. |
||
150 | * |
||
151 | * @param \Illuminate\Http\Request $request |
||
152 | * |
||
153 | * @return self |
||
154 | */ |
||
155 | 6 | private function setRequest(Request $request) |
|
169 | |||
170 | /* ----------------------------------------------------------------- |
||
171 | | Main Methods |
||
172 | | ----------------------------------------------------------------- |
||
173 | */ |
||
174 | |||
175 | /** |
||
176 | * Start the tracking. |
||
177 | * |
||
178 | * @param \Illuminate\Http\Request $request |
||
179 | */ |
||
180 | 6 | public function trackRequest(Request $request) |
|
195 | |||
196 | /** |
||
197 | * Track the matched route. |
||
198 | * |
||
199 | * @param \Illuminate\Routing\Route $route |
||
200 | * @param \Illuminate\Http\Request $request |
||
201 | */ |
||
202 | 6 | public function trackMatchedRoute(Route $route, Request $request) |
|
216 | |||
217 | /** |
||
218 | * Track the exception. |
||
219 | * |
||
220 | * @param \Exception $exception |
||
221 | */ |
||
222 | 35 | public function trackException(Exception $exception) |
|
230 | |||
231 | /** |
||
232 | * Enable the tracking. |
||
233 | */ |
||
234 | 117 | public function enable() |
|
238 | |||
239 | /** |
||
240 | * Disable the tracking. |
||
241 | */ |
||
242 | 3 | public function disable() |
|
246 | |||
247 | /* ----------------------------------------------------------------- |
||
248 | | Check Methods |
||
249 | | ----------------------------------------------------------------- |
||
250 | */ |
||
251 | |||
252 | /** |
||
253 | * Check if the tracker is enabled. |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | 117 | public function isEnabled() |
|
261 | |||
262 | /** |
||
263 | * Track the trackable if enabled. |
||
264 | * |
||
265 | * @param string $key |
||
266 | * @param \Closure $callback |
||
267 | * @param mixed|null $default |
||
268 | * |
||
269 | * @return mixed |
||
270 | */ |
||
271 | 105 | private function trackIfEnabled($key, \Closure $callback, $default = null) |
|
277 | |||
278 | /* ----------------------------------------------------------------- |
||
279 | | Other Methods |
||
280 | | ----------------------------------------------------------------- |
||
281 | */ |
||
282 | |||
283 | /** |
||
284 | * Merge visitor data. |
||
285 | * |
||
286 | * @param array $data |
||
287 | * |
||
288 | * @return self |
||
289 | */ |
||
290 | 6 | private function mergeVisitorData(array $data) |
|
296 | |||
297 | /** |
||
298 | * Merge visitor activity data. |
||
299 | * |
||
300 | * @param array $data |
||
301 | * |
||
302 | * @return self |
||
303 | */ |
||
304 | 9 | private function mergeVisitorActivityData(array $data) |
|
310 | |||
311 | /** |
||
312 | * Get the stored visitor id. |
||
313 | * |
||
314 | * @return int |
||
315 | */ |
||
316 | 6 | private function getVisitorId() |
|
336 | |||
337 | /** |
||
338 | * Track the path. |
||
339 | * |
||
340 | * @return int|null |
||
341 | */ |
||
342 | 2 | private function getPathId() |
|
350 | |||
351 | /** |
||
352 | * Track the query. |
||
353 | * |
||
354 | * @return int|null |
||
355 | */ |
||
356 | 2 | private function getQueryId() |
|
364 | |||
365 | /** |
||
366 | * Get the user id. |
||
367 | * |
||
368 | * @return int|null |
||
369 | */ |
||
370 | 2 | private function getUserId() |
|
376 | |||
377 | /** |
||
378 | * Get the tracked device id. |
||
379 | * |
||
380 | * @return int|null |
||
381 | */ |
||
382 | 2 | private function getDeviceId() |
|
388 | |||
389 | /** |
||
390 | * Get the tracked ip address ip. |
||
391 | * |
||
392 | * @return int|null |
||
393 | */ |
||
394 | 2 | private function getGeoIpId() |
|
402 | |||
403 | /** |
||
404 | * Get the tracked user agent id. |
||
405 | * |
||
406 | * @return int|null |
||
407 | */ |
||
408 | 2 | private function getAgentId() |
|
414 | |||
415 | /** |
||
416 | * Get the tracked referer id. |
||
417 | * |
||
418 | * @return int|null |
||
419 | */ |
||
420 | 2 | private function getRefererId() |
|
429 | |||
430 | /** |
||
431 | * Get the tracked cookie id. |
||
432 | * |
||
433 | * @return int|null |
||
434 | */ |
||
435 | 2 | private function getCookieId() |
|
443 | |||
444 | /** |
||
445 | * Get the tracked language id. |
||
446 | * |
||
447 | * @return int|null |
||
448 | */ |
||
449 | private function getLanguageId() |
||
455 | |||
456 | /** |
||
457 | * Check if the visitor is a robot. |
||
458 | * |
||
459 | * @return bool |
||
460 | */ |
||
461 | 6 | protected function isRobot() |
|
468 | } |
||
469 |
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.