1 | <?php namespace Arcanedev\LaravelTracker; |
||
15 | class Tracker implements TrackerContract |
||
16 | { |
||
17 | /* ------------------------------------------------------------------------------------------------ |
||
18 | | Traits |
||
19 | | ------------------------------------------------------------------------------------------------ |
||
20 | */ |
||
21 | use Traits\TrackersMaker; |
||
22 | |||
23 | /* ------------------------------------------------------------------------------------------------ |
||
24 | | Properties |
||
25 | | ------------------------------------------------------------------------------------------------ |
||
26 | */ |
||
27 | /** |
||
28 | * The application container. |
||
29 | * |
||
30 | * @var \Illuminate\Contracts\Foundation\Application |
||
31 | */ |
||
32 | protected $app; |
||
33 | |||
34 | /** |
||
35 | * The request instance. |
||
36 | * |
||
37 | * @var \Illuminate\Http\Request |
||
38 | */ |
||
39 | private $request; |
||
40 | |||
41 | /** |
||
42 | * Tracking enabled status. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $enabled = false; |
||
47 | |||
48 | /** |
||
49 | * The current session data. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $sessionData = [ |
||
54 | 'user_id' => null, |
||
55 | 'device_id' => null, |
||
56 | 'agent_id' => null, |
||
57 | 'geoip_id' => null, |
||
58 | 'referer_id' => null, |
||
59 | 'cookie_id' => null, |
||
60 | 'language_id' => null, |
||
61 | 'client_ip' => '', |
||
62 | 'is_robot' => false, |
||
63 | 'user_agent' => '', |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * The current session activity data. |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $sessionActivityData = [ |
||
72 | 'session_id' => null, |
||
73 | 'path_id' => null, |
||
74 | 'query_id' => null, |
||
75 | 'referer_id' => null, |
||
76 | 'route_path_id' => null, |
||
77 | 'error_id' => null, |
||
78 | 'method' => '', |
||
79 | 'is_ajax' => false, |
||
80 | 'is_secure' => false, |
||
81 | 'is_json' => false, |
||
82 | 'wants_json' => false, |
||
83 | ]; |
||
84 | |||
85 | /* ------------------------------------------------------------------------------------------------ |
||
86 | | Constructor |
||
87 | | ------------------------------------------------------------------------------------------------ |
||
88 | */ |
||
89 | /** |
||
90 | * Tracker constructor. |
||
91 | * |
||
92 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
93 | */ |
||
94 | 234 | public function __construct(Application $app) |
|
99 | |||
100 | /* ------------------------------------------------------------------------------------------------ |
||
101 | | Getters & Setters |
||
102 | | ------------------------------------------------------------------------------------------------ |
||
103 | */ |
||
104 | /** |
||
105 | * Get the application instance. |
||
106 | * |
||
107 | * @return \Illuminate\Contracts\Foundation\Application |
||
108 | */ |
||
109 | 234 | protected function app() |
|
113 | |||
114 | /** |
||
115 | * Get the config repository. |
||
116 | * |
||
117 | * @return \Illuminate\Contracts\Config\Repository |
||
118 | */ |
||
119 | 234 | private function config() |
|
123 | |||
124 | /** |
||
125 | * Get the tracker config. |
||
126 | * |
||
127 | * @param string $key |
||
128 | * @param mixed|null $default |
||
129 | * |
||
130 | * @return mixed |
||
131 | */ |
||
132 | 234 | private function getConfig($key, $default = null) |
|
136 | |||
137 | /** |
||
138 | * Set the request. |
||
139 | * |
||
140 | * @param \Illuminate\Http\Request $request |
||
141 | * |
||
142 | * @return self |
||
143 | */ |
||
144 | 12 | private function setRequest(Request $request) |
|
158 | |||
159 | /* ------------------------------------------------------------------------------------------------ |
||
160 | | Main Functions |
||
161 | | ------------------------------------------------------------------------------------------------ |
||
162 | */ |
||
163 | /** |
||
164 | * Start the tracking. |
||
165 | * |
||
166 | * @param \Illuminate\Http\Request $request |
||
167 | */ |
||
168 | 12 | public function trackRequest(Request $request) |
|
183 | |||
184 | /** |
||
185 | * Track the matched route. |
||
186 | * |
||
187 | * @param \Illuminate\Routing\Route $route |
||
188 | * @param \Illuminate\Http\Request $request |
||
189 | */ |
||
190 | 12 | public function trackMatchedRoute(Route $route, Request $request) |
|
204 | |||
205 | /** |
||
206 | * Track the exception. |
||
207 | * |
||
208 | * @param \Exception $exception |
||
209 | */ |
||
210 | 4 | public function trackException(Exception $exception) |
|
218 | |||
219 | /** |
||
220 | * Enable the tracking. |
||
221 | */ |
||
222 | 234 | public function enable() |
|
226 | |||
227 | /** |
||
228 | * Disable the tracking. |
||
229 | */ |
||
230 | 6 | public function disable() |
|
234 | |||
235 | /* ------------------------------------------------------------------------------------------------ |
||
236 | | Check Functions |
||
237 | | ------------------------------------------------------------------------------------------------ |
||
238 | */ |
||
239 | /** |
||
240 | * Check if the tracker is enabled. |
||
241 | * |
||
242 | * @return bool |
||
243 | */ |
||
244 | 234 | public function isEnabled() |
|
248 | |||
249 | /** |
||
250 | * Track the trackable if enabled. |
||
251 | * |
||
252 | * @param string $key |
||
253 | * @param \Closure $callback |
||
254 | * @param mixed|null $default |
||
255 | * |
||
256 | * @return mixed |
||
257 | */ |
||
258 | 16 | private function trackIfEnabled($key, \Closure $callback, $default = null) |
|
264 | |||
265 | /* ------------------------------------------------------------------------------------------------ |
||
266 | | Other Functions |
||
267 | | ------------------------------------------------------------------------------------------------ |
||
268 | */ |
||
269 | /** |
||
270 | * Merge session data. |
||
271 | * |
||
272 | * @param array $data |
||
273 | * |
||
274 | * @return self |
||
275 | */ |
||
276 | 12 | private function mergeSessionData(array $data) |
|
282 | |||
283 | /** |
||
284 | * Merge session activity data. |
||
285 | * |
||
286 | * @param array $data |
||
287 | * |
||
288 | * @return self |
||
289 | */ |
||
290 | 16 | private function mergeSessionActivityData(array $data) |
|
296 | |||
297 | /** |
||
298 | * Get the stored session id. |
||
299 | * |
||
300 | * @return int |
||
301 | */ |
||
302 | 12 | private function getSessionId() |
|
322 | |||
323 | /** |
||
324 | * Track the path. |
||
325 | * |
||
326 | * @return int|null |
||
327 | */ |
||
328 | 12 | private function getPathId() |
|
336 | |||
337 | /** |
||
338 | * Track the query. |
||
339 | * |
||
340 | * @return int|null |
||
341 | */ |
||
342 | 12 | private function getQueryId() |
|
350 | |||
351 | /** |
||
352 | * Get the user id. |
||
353 | * |
||
354 | * @return int|null |
||
355 | */ |
||
356 | 12 | private function getUserId() |
|
362 | |||
363 | /** |
||
364 | * Get the tracked device id. |
||
365 | * |
||
366 | * @return int|null |
||
367 | */ |
||
368 | 12 | private function getDeviceId() |
|
374 | |||
375 | /** |
||
376 | * Get the tracked ip address ip. |
||
377 | * |
||
378 | * @return int|null |
||
379 | */ |
||
380 | 12 | private function getGeoIpId() |
|
388 | |||
389 | /** |
||
390 | * Get the tracked user agent id. |
||
391 | * |
||
392 | * @return int|null |
||
393 | */ |
||
394 | 12 | private function getAgentId() |
|
400 | |||
401 | /** |
||
402 | * Get the tracked referer id. |
||
403 | * |
||
404 | * @return int|null |
||
405 | */ |
||
406 | 12 | private function getRefererId() |
|
415 | |||
416 | /** |
||
417 | * Get the tracked cookie id. |
||
418 | * |
||
419 | * @return int|null |
||
420 | */ |
||
421 | 12 | private function getCookieId() |
|
429 | |||
430 | /** |
||
431 | * Get the tracked language id. |
||
432 | * |
||
433 | * @return int|null |
||
434 | */ |
||
435 | private function getLanguageId() |
||
441 | |||
442 | /** |
||
443 | * Check if the visitor is a robot. |
||
444 | * |
||
445 | * @return bool |
||
446 | */ |
||
447 | 12 | protected function isRobot() |
|
454 | } |
||
455 |
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.