1 | <?php namespace Arcanedev\LaravelTracker; |
||
16 | class Tracker implements TrackerContract |
||
17 | { |
||
18 | /* ------------------------------------------------------------------------------------------------ |
||
19 | | Properties |
||
20 | | ------------------------------------------------------------------------------------------------ |
||
21 | */ |
||
22 | /** |
||
23 | * The application container. |
||
24 | * |
||
25 | * @var \Illuminate\Contracts\Foundation\Application |
||
26 | */ |
||
27 | protected $app; |
||
28 | |||
29 | /** |
||
30 | * The request instance. |
||
31 | * |
||
32 | * @var \Illuminate\Http\Request |
||
33 | */ |
||
34 | private $request; |
||
35 | |||
36 | /** |
||
37 | * The tracking manager. |
||
38 | * |
||
39 | * @var \Arcanedev\LaravelTracker\Contracts\TrackingManager |
||
40 | */ |
||
41 | private $manager; |
||
42 | |||
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 | 'referrer_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 | 'referrer_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 | * @param \Arcanedev\LaravelTracker\Contracts\TrackingManager $manager |
||
94 | */ |
||
95 | 216 | public function __construct(Application $app, TrackingManagerContract $manager) |
|
101 | |||
102 | /* ------------------------------------------------------------------------------------------------ |
||
103 | | Getters & Setters |
||
104 | | ------------------------------------------------------------------------------------------------ |
||
105 | */ |
||
106 | /** |
||
107 | * Get the config repository. |
||
108 | * |
||
109 | * @return \Illuminate\Contracts\Config\Repository |
||
110 | */ |
||
111 | 216 | private function config() |
|
115 | |||
116 | /** |
||
117 | * Get the tracker config. |
||
118 | * |
||
119 | * @param string $key |
||
120 | * @param mixed|null $default |
||
121 | * |
||
122 | * @return mixed |
||
123 | */ |
||
124 | 216 | private function getConfig($key, $default = null) |
|
128 | |||
129 | /** |
||
130 | * Set the request. |
||
131 | * |
||
132 | * @param \Illuminate\Http\Request $request |
||
133 | * |
||
134 | * @return self |
||
135 | */ |
||
136 | 6 | private function setRequest(Request $request) |
|
150 | |||
151 | /** |
||
152 | * Get the user agent parser. |
||
153 | * |
||
154 | * @return \Arcanedev\LaravelTracker\Contracts\Parsers\UserAgentParser |
||
155 | */ |
||
156 | 6 | public function getUserAgentParser() |
|
160 | |||
161 | /** |
||
162 | * Merge session data. |
||
163 | * |
||
164 | * @param array $data |
||
165 | * |
||
166 | * @return self |
||
167 | */ |
||
168 | 6 | private function mergeSessionData(array $data) |
|
174 | |||
175 | /** |
||
176 | * Merge session activity data. |
||
177 | * |
||
178 | * @param array $data |
||
179 | * |
||
180 | * @return self |
||
181 | */ |
||
182 | 10 | private function mergeSessionActivityData(array $data) |
|
188 | |||
189 | /* ------------------------------------------------------------------------------------------------ |
||
190 | | Main Functions |
||
191 | | ------------------------------------------------------------------------------------------------ |
||
192 | */ |
||
193 | /** |
||
194 | * Start the tracking. |
||
195 | * |
||
196 | * @param \Illuminate\Http\Request $request |
||
197 | */ |
||
198 | 6 | public function track(Request $request) |
|
213 | |||
214 | /** |
||
215 | * Track the matched route. |
||
216 | * |
||
217 | * @param \Illuminate\Routing\Route $route |
||
218 | * @param \Illuminate\Http\Request $request |
||
219 | */ |
||
220 | 6 | public function trackMatchedRoute(Route $route, Request $request) |
|
232 | |||
233 | /** |
||
234 | * Track the exception. |
||
235 | * |
||
236 | * @param \Exception $exception |
||
237 | */ |
||
238 | 4 | public function trackException(\Exception $exception) |
|
246 | |||
247 | /** |
||
248 | * Enable the tracker. |
||
249 | */ |
||
250 | 6 | public function enable() |
|
254 | |||
255 | /** |
||
256 | * Disable the tracker. |
||
257 | */ |
||
258 | 6 | public function disable() |
|
262 | |||
263 | /* ------------------------------------------------------------------------------------------------ |
||
264 | | Check Functions |
||
265 | | ------------------------------------------------------------------------------------------------ |
||
266 | */ |
||
267 | /** |
||
268 | * Check if the tracker is enabled. |
||
269 | * |
||
270 | * @return bool |
||
271 | */ |
||
272 | 28 | public function isEnabled() |
|
276 | |||
277 | /* ------------------------------------------------------------------------------------------------ |
||
278 | | Other Functions |
||
279 | | ------------------------------------------------------------------------------------------------ |
||
280 | */ |
||
281 | /** |
||
282 | * Get the stored session id. |
||
283 | * |
||
284 | * @return int |
||
285 | */ |
||
286 | 6 | private function getSessionId() |
|
305 | |||
306 | /** |
||
307 | * Track the path. |
||
308 | * |
||
309 | * @return int|null |
||
310 | */ |
||
311 | 6 | private function getPathId() |
|
319 | |||
320 | /** |
||
321 | * Track the query. |
||
322 | * |
||
323 | * @return int|null |
||
324 | */ |
||
325 | 6 | private function getQueryId() |
|
333 | |||
334 | /** |
||
335 | * Get the user id. |
||
336 | * |
||
337 | * @return int|null |
||
338 | */ |
||
339 | 6 | private function getUserId() |
|
345 | |||
346 | /** |
||
347 | * Get the tracked device id. |
||
348 | * |
||
349 | * @return int|null |
||
350 | */ |
||
351 | 6 | private function getDeviceId() |
|
357 | |||
358 | /** |
||
359 | * Get the tracked ip address ip. |
||
360 | * |
||
361 | * @return int|null |
||
362 | */ |
||
363 | 6 | private function getGeoIpId() |
|
371 | |||
372 | /** |
||
373 | * Get the tracked user agent id. |
||
374 | * |
||
375 | * @return int|null |
||
376 | */ |
||
377 | 6 | private function getAgentId() |
|
383 | |||
384 | /** |
||
385 | * Get the tracked referer id. |
||
386 | * |
||
387 | * @return int|null |
||
388 | */ |
||
389 | 6 | private function getRefererId() |
|
398 | |||
399 | /** |
||
400 | * Get the tracked cookie id. |
||
401 | * |
||
402 | * @return int|null |
||
403 | */ |
||
404 | 6 | private function getCookieId() |
|
412 | |||
413 | /** |
||
414 | * Get the tracked language id. |
||
415 | * |
||
416 | * @return int|null |
||
417 | */ |
||
418 | private function getLanguageId() |
||
424 | |||
425 | /** |
||
426 | * Check if the visitor is a robot. |
||
427 | * |
||
428 | * @return bool |
||
429 | */ |
||
430 | 6 | protected function isRobot() |
|
437 | |||
438 | /** |
||
439 | * Track the trackable if enabled. |
||
440 | * |
||
441 | * @param string $key |
||
442 | * @param \Closure $callback |
||
443 | * @param mixed|null $default |
||
444 | * |
||
445 | * @return mixed |
||
446 | */ |
||
447 | 10 | private function trackIfEnabled($key, \Closure $callback, $default = null) |
|
453 | } |
||
454 |
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.