Completed
Push — master ( 76e8e7...f18538 )
by Antonio Carlos
14s queued 11s
created

RepositoryManager::getRefererId()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
namespace PragmaRX\Tracker\Data;
4
5
use Illuminate\Routing\Router as IlluminateRouter;
6
use Illuminate\Session\Store as IlluminateSession;
7
use PragmaRX\Support\Config;
8
use PragmaRX\Support\GeoIp\GeoIp;
9
use PragmaRX\Tracker\Data\Repositories\Agent;
10
use PragmaRX\Tracker\Data\Repositories\Connection;
11
use PragmaRX\Tracker\Data\Repositories\Cookie;
12
use PragmaRX\Tracker\Data\Repositories\Device;
13
use PragmaRX\Tracker\Data\Repositories\Domain;
14
use PragmaRX\Tracker\Data\Repositories\Error;
15
use PragmaRX\Tracker\Data\Repositories\Event;
16
use PragmaRX\Tracker\Data\Repositories\EventLog;
17
use PragmaRX\Tracker\Data\Repositories\GeoIp as GeoIpRepository;
18
use PragmaRX\Tracker\Data\Repositories\Language;
19
use PragmaRX\Tracker\Data\Repositories\Log;
20
use PragmaRX\Tracker\Data\Repositories\Path;
21
use PragmaRX\Tracker\Data\Repositories\Query;
22
use PragmaRX\Tracker\Data\Repositories\QueryArgument;
23
use PragmaRX\Tracker\Data\Repositories\Referer;
24
use PragmaRX\Tracker\Data\Repositories\Route;
25
use PragmaRX\Tracker\Data\Repositories\RoutePath;
26
use PragmaRX\Tracker\Data\Repositories\RoutePathParameter;
27
use PragmaRX\Tracker\Data\Repositories\Session;
28
use PragmaRX\Tracker\Data\Repositories\SqlQuery;
29
use PragmaRX\Tracker\Data\Repositories\SqlQueryBinding;
30
use PragmaRX\Tracker\Data\Repositories\SqlQueryBindingParameter;
31
use PragmaRX\Tracker\Data\Repositories\SqlQueryLog;
32
use PragmaRX\Tracker\Data\Repositories\SystemClass;
33
use PragmaRX\Tracker\Services\Authentication;
34
use PragmaRX\Tracker\Support\CrawlerDetector;
35
use PragmaRX\Tracker\Support\LanguageDetect;
36
use PragmaRX\Tracker\Support\MobileDetect;
37
38
class RepositoryManager implements RepositoryManagerInterface
39
{
40
    /**
41
     * @var Path
42
     */
43
    private $pathRepository;
44
45
    /**
46
     * @var Query
47
     */
48
    private $queryRepository;
49
50
    /**
51
     * @var QueryArgument
52
     */
53
    private $queryArgumentRepository;
54
55
    /**
56
     * @var Domain
57
     */
58
    private $domainRepository;
59
60
    /**
61
     * @var Referer
62
     */
63
    private $refererRepository;
64
65
    /**
66
     * @var Repositories\Route
67
     */
68
    private $routeRepository;
69
70
    /**
71
     * @var Repositories\RoutePath
72
     */
73
    private $routePathRepository;
74
75
    /**
76
     * @var Repositories\RoutePathParameter
77
     */
78
    private $routePathParameterRepository;
79
80
    /**
81
     * @var Error
82
     */
83
    private $errorRepository;
84
85
    /**
86
     * @var GeoIP
87
     */
88
    private $geoIp;
89
90
    private $geoIpRepository;
91
92
    /**
93
     * @var Repositories\SqlQuery
94
     */
95
    private $sqlQueryRepository;
96
97
    /**
98
     * @var Repositories\SqlQueryBinding
99
     */
100
    private $sqlQueryBindingRepository;
101
102
    /**
103
     * @var Repositories\SqlQueryLog
104
     */
105
    private $sqlQueryLogRepository;
106
107
    private $sqlQueryBindingParameterRepository;
108
109
    /**
110
     * @var Repositories\Connection
111
     */
112
    private $connectionRepository;
113
114
    /**
115
     * @var Repositories\Event
116
     */
117
    private $eventRepository;
118
119
    /**
120
     * @var Repositories\EventLog
121
     */
122
    private $eventLogRepository;
123
124
    /**
125
     * @var Repositories\SystemClass
126
     */
127
    private $systemClassRepository;
128
129
    private $userAgentParser;
130
131
    /**
132
     * @var CrawlerDetector
133
     */
134
    private $crawlerDetector;
135
136
    /**
137
     * @var Repositories\Language
138
     */
139
    private $languageRepository;
140
141
    /**
142
     * @var Repositories\Language
143
     */
144
    private $languageDetect;
145
146
    /**
147
     * @param \PragmaRX\Tracker\Support\UserAgentParser|null $userAgentParser
148
     */
149
    public function __construct(
150
        GeoIP $geoIp,
151
        MobileDetect $mobileDetect,
152
        $userAgentParser,
153
        Authentication $authentication,
154
        IlluminateSession $session,
155
        Config $config,
156
        Session $sessionRepository,
157
        Log $logRepository,
158
        Path $pathRepository,
159
        Query $queryRepository,
160
        QueryArgument $queryArgumentRepository,
161
        Agent $agentRepository,
162
        Device $deviceRepository,
163
        Cookie $cookieRepository,
164
        Domain $domainRepository,
165
        Referer $refererRepository,
166
        Route $routeRepository,
167
        RoutePath $routePathRepository,
168
        RoutePathParameter $routePathParameterRepository,
169
        Error $errorRepository,
170
        GeoIpRepository $geoIpRepository,
171
        SqlQuery $sqlQueryRepository,
172
        SqlQueryBinding $sqlQueryBindingRepository,
173
        SqlQueryBindingParameter $sqlQueryBindingParameterRepository,
174
        SqlQueryLog $sqlQueryLogRepository,
175
        Connection $connectionRepository,
176
        Event $eventRepository,
177
        EventLog $eventLogRepository,
178
        SystemClass $systemClassRepository,
179
        CrawlerDetector $crawlerDetector,
180
        Language $languageRepository,
181
        LanguageDetect $languageDetect
182
    ) {
183
        $this->authentication = $authentication;
0 ignored issues
show
Bug introduced by
The property authentication does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
184
185
        $this->mobileDetect = $mobileDetect;
0 ignored issues
show
Bug introduced by
The property mobileDetect does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
186
187
        $this->userAgentParser = $userAgentParser;
188
189
        $this->session = $session;
0 ignored issues
show
Bug introduced by
The property session does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
190
191
        $this->config = $config;
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
192
193
        $this->geoIp = $geoIp;
0 ignored issues
show
Documentation Bug introduced by
It seems like $geoIp of type object<PragmaRX\Support\GeoIp\GeoIp> is incompatible with the declared type object<PragmaRX\Tracker\Data\GeoIP> of property $geoIp.

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...
194
195
        $this->sessionRepository = $sessionRepository;
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
196
197
        $this->logRepository = $logRepository;
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
198
199
        $this->pathRepository = $pathRepository;
200
201
        $this->queryRepository = $queryRepository;
202
203
        $this->queryArgumentRepository = $queryArgumentRepository;
204
205
        $this->agentRepository = $agentRepository;
0 ignored issues
show
Bug introduced by
The property agentRepository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
206
207
        $this->deviceRepository = $deviceRepository;
0 ignored issues
show
Bug introduced by
The property deviceRepository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
208
209
        $this->cookieRepository = $cookieRepository;
0 ignored issues
show
Bug introduced by
The property cookieRepository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
210
211
        $this->domainRepository = $domainRepository;
212
213
        $this->refererRepository = $refererRepository;
214
215
        $this->routeRepository = $routeRepository;
216
217
        $this->routePathRepository = $routePathRepository;
218
219
        $this->routePathParameterRepository = $routePathParameterRepository;
220
221
        $this->errorRepository = $errorRepository;
222
223
        $this->geoIpRepository = $geoIpRepository;
224
225
        $this->sqlQueryRepository = $sqlQueryRepository;
226
227
        $this->sqlQueryBindingRepository = $sqlQueryBindingRepository;
228
229
        $this->sqlQueryBindingParameterRepository = $sqlQueryBindingParameterRepository;
230
231
        $this->sqlQueryLogRepository = $sqlQueryLogRepository;
232
233
        $this->connectionRepository = $connectionRepository;
234
235
        $this->eventRepository = $eventRepository;
236
237
        $this->eventLogRepository = $eventLogRepository;
238
239
        $this->systemClassRepository = $systemClassRepository;
240
241
        $this->crawlerDetector = $crawlerDetector;
242
243
        $this->languageRepository = $languageRepository;
244
245
        $this->languageDetect = $languageDetect;
0 ignored issues
show
Documentation Bug introduced by
It seems like $languageDetect of type object<PragmaRX\Tracker\Support\LanguageDetect> is incompatible with the declared type object<PragmaRX\Tracker\...\Repositories\Language> of property $languageDetect.

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...
246
    }
247
248
    public function checkSessionData($newData, $currentData)
249
    {
250
        if ($newData && $currentData && $newData !== $currentData) {
251
            $newData = $this->updateSessionData($newData);
252
        }
253
254
        return $newData;
255
    }
256
257
    public function createLog($data)
258
    {
259
        $this->logRepository->createLog($data);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
260
261
        $this->sqlQueryRepository->fire();
262
    }
263
264
    private function createRoutePathParameter($route_path_id, $parameter, $value)
265
    {
266
        return $this->routePathParameterRepository->create(
267
            [
268
                'route_path_id' => $route_path_id,
269
                'parameter'     => $parameter,
270
                'value'         => $value,
271
            ]
272
        );
273
    }
274
275
    public function errors($minutes, $results)
276
    {
277
        return $this->logRepository->getErrors($minutes, $results);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
278
    }
279
280
    public function events($minutes, $results)
281
    {
282
        return $this->eventRepository->getAll($minutes, $results);
283
    }
284
285
    public function findOrCreateAgent($data)
286
    {
287
        return $this->agentRepository->findOrCreate($data, ['name_hash']);
288
    }
289
290
    public function findOrCreateDevice($data)
291
    {
292
        return $this->deviceRepository->findOrCreate($data, ['kind', 'model', 'platform', 'platform_version']);
293
    }
294
295
    public function findOrCreateLanguage($data)
296
    {
297
        return $this->languageRepository->findOrCreate($data, ['preference', 'language-range']);
298
    }
299
300
    public function findOrCreatePath($path)
301
    {
302
        return $this->pathRepository->findOrCreate($path, ['path']);
303
    }
304
305
    public function findOrCreateQuery($data)
306
    {
307
        $id = $this->queryRepository->findOrCreate($data, ['query'], $created);
308
309
        if ($created) {
310
            foreach ($data['arguments'] as $argument => $value) {
311
                if (is_array($value)) {
312
                    $value = multi_implode(',', $value);
313
                }
314
315
                $this->queryArgumentRepository->create(
316
                    [
317
                        'query_id' => $id,
318
                        'argument' => $argument,
319
                        'value'    => empty($value) ? '' : $value,
320
                    ]
321
                );
322
            }
323
        }
324
325
        return $id;
326
    }
327
328
    public function findOrCreateSession($data)
329
    {
330
        return $this->sessionRepository->findOrCreate($data, ['uuid']);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
331
    }
332
333
    public function getAgentId()
334
    {
335
        return $this->findOrCreateAgent($this->getCurrentAgentArray());
336
    }
337
338
    public function getAllSessions()
339
    {
340
        return $this->sessionRepository->all();
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
341
    }
342
343
    public function getCookieId()
344
    {
345
        return $this->cookieRepository->getId();
346
    }
347
348
    public function getCurrentAgentArray()
349
    {
350
        return [
351
            'name' => $name = $this->getCurrentUserAgent() ?: 'Other',
352
353
            'browser' => $this->userAgentParser->userAgent->family,
354
355
            'browser_version' => $this->userAgentParser->getUserAgentVersion(),
356
357
            'name_hash' => hash('sha256', $name),
358
        ];
359
    }
360
361
    public function getCurrentDeviceProperties()
362
    {
363
        if ($properties = $this->getDevice()) {
364
            $properties['platform'] = $this->getOperatingSystemFamily();
365
366
            $properties['platform_version'] = $this->getOperatingSystemVersion();
367
        }
368
369
        return $properties;
370
    }
371
372
    public function getCurrentUserAgent()
373
    {
374
        return $this->userAgentParser->originalUserAgent;
375
    }
376
377
    public function getCurrentUserId()
378
    {
379
        return $this->authentication->getCurrentUserId();
380
    }
381
382
    /**
383
     * @return array
384
     */
385
    private function getDevice()
386
    {
387
        try {
388
            return $this->mobileDetect->detectDevice();
389
        } catch (\Exception $e) {
390
            return;
391
        }
392
    }
393
394
    private function getLanguage()
395
    {
396
        try {
397
            return $this->languageDetect->detectLanguage();
0 ignored issues
show
Bug introduced by
The method detectLanguage() does not seem to exist on object<PragmaRX\Tracker\...\Repositories\Language>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
398
        } catch (\Exception $e) {
399
            return;
400
        }
401
    }
402
403
    public function getCurrentLanguage()
404
    {
405
        if ($languages = $this->getLanguage()) {
406
            $languages['preference'] = $this->languageDetect->getLanguagePreference();
0 ignored issues
show
Bug introduced by
The method getLanguagePreference() does not seem to exist on object<PragmaRX\Tracker\...\Repositories\Language>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
407
408
            $languages['language-range'] = $this->languageDetect->getLanguageRange();
0 ignored issues
show
Bug introduced by
The method getLanguageRange() does not seem to exist on object<PragmaRX\Tracker\...\Repositories\Language>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
409
        }
410
411
        return $languages;
412
    }
413
414
    public function getDomainId($domain)
415
    {
416
        return $this->domainRepository->findOrCreate(
417
            ['name' => $domain],
418
            ['name']
419
        );
420
    }
421
422
    public function getGeoIpId($clientIp)
423
    {
424
        $id = null;
425
426
        if ($geoIpData = $this->geoIp->searchAddr($clientIp)) {
427
            $id = $this->geoIpRepository->findOrCreate(
428
                $geoIpData,
429
                ['latitude', 'longitude']
430
            );
431
        }
432
433
        return $id;
434
    }
435
436
    public function getLastSessions($minutes, $results)
437
    {
438
        return $this->sessionRepository->last($minutes, $results);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
439
    }
440
441
    /**
442
     * @return mixed
443
     */
444
    private function getOperatingSystemFamily()
445
    {
446
        try {
447
            return $this->userAgentParser->operatingSystem->family;
448
        } catch (\Exception $e) {
0 ignored issues
show
Unused Code introduced by
catch (\Exception $e) { return; } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
449
            return;
450
        }
451
    }
452
453
    /**
454
     * @return mixed
455
     */
456
    private function getOperatingSystemVersion()
457
    {
458
        try {
459
            return $this->userAgentParser->getOperatingSystemVersion();
460
        } catch (\Exception $e) {
461
            return;
462
        }
463
    }
464
465
    public function getQueryId($query)
466
    {
467
        if (!$query) {
468
            return;
469
        }
470
471
        return $this->findOrCreateQuery($query);
472
    }
473
474
    public function getRefererId($referer)
475
    {
476
        if ($referer) {
477
            $url = parse_url($referer);
478
479
            if (!isset($url['host'])) {
480
                return;
481
            }
482
483
            $parts = explode('.', $url['host']);
484
485
            $domain = array_pop($parts);
486
487
            if (count($parts) > 0) {
488
                $domain = array_pop($parts).'.'.$domain;
489
            }
490
491
            $domain_id = $this->getDomainId($domain);
492
493
            return $this->refererRepository->store($referer, $url['host'], $domain_id);
494
        }
495
    }
496
497
    /**
498
     * @param $request
499
     *
500
     * @return mixed
501
     */
502
    private function getRequestPath($request)
503
    {
504
        if (is_string($request)) {
505
            return $request;
506
        }
507
508
        if (is_array($request)) {
509
            return $request['path'];
510
        }
511
512
        return $request->path();
513
    }
514
515
    /**
516
     * @param $route
517
     *
518
     * @return mixed
519
     */
520
    private function getRouteAction($route)
521
    {
522
        if (is_string($route)) {
523
            return '';
524
        }
525
526
        if (is_array($route)) {
527
            return $route['action'];
528
        }
529
530
        return $route->currentRouteAction();
531
    }
532
533
    /**
534
     * @param string $name
535
     */
536
    private function getRouteId($name, $action)
537
    {
538
        return $this->routeRepository->findOrCreate(
539
            ['name' => $name, 'action' => $action],
540
            ['name', 'action']
541
        );
542
    }
543
544
    /**
545
     * @param $route
546
     *
547
     * @return string
548
     */
549
    private function getRouteName($route)
550
    {
551
        if (is_string($route)) {
552
            return $route;
553
        }
554
555
        if (is_array($route)) {
556
            return $route['name'];
557
        }
558
559
        if ($name = $route->current()->getName()) {
560
            return $name;
561
        }
562
563
        $action = $route->current()->getAction();
564
565
        if ($name = isset($action['as']) ? $action['as'] : null) {
566
            return $name;
567
        }
568
569
        return '/'.$route->current()->uri();
570
    }
571
572
    /**
573
     * @param bool $created
574
     */
575
    private function getRoutePath($route_id, $path, &$created = null)
576
    {
577
        return $this->routePathRepository->findOrCreate(
578
            ['route_id' => $route_id, 'path' => $path],
579
            ['route_id', 'path'],
580
            $created
0 ignored issues
show
Bug introduced by
It seems like $created defined by parameter $created on line 575 can also be of type null; however, PragmaRX\Tracker\Data\Re...ository::findOrCreate() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
581
        );
582
    }
583
584
    public function getRoutePathId($route, $request)
585
    {
586
        $route_id = $this->getRouteId(
587
            $this->getRouteName($route),
588
            $this->getRouteAction($route)
589
                ?: 'closure'
590
        );
591
592
        $created = false;
593
594
        $route_path_id = $this->getRoutePath(
595
            $route_id,
596
            $this->getRequestPath($request),
597
            $created
598
        );
599
600
        if ($created && $route instanceof IlluminateRouter && $route->current()) {
601
            foreach ($route->current()->parameters() as $parameter => $value) {
602
                // When the parameter value is a whole model, we have
603
                // two options left:
604
                //
605
                //  1) Return model id, if it's available as 'id'
606
                //  2) Return null (not ideal, but, what could we do?)
607
                //
608
                // Should we store the whole model? Not really useful, right?
609
610
                if ($value instanceof \Illuminate\Database\Eloquent\Model) {
611
                    $model_id = null;
612
613
                    foreach ($this->config->get('id_columns_names', ['id']) as $column) {
614
                        if (property_exists($value, $column)) {
615
                            $model_id = $value->$column;
616
617
                            break;
618
                        }
619
                    }
620
621
                    $value = $model_id;
622
                }
623
624
                if ($route_path_id && $parameter && $value) {
625
                    $this->createRoutePathParameter($route_path_id, $parameter, $value);
626
                }
627
            }
628
        }
629
630
        return $route_path_id;
631
    }
632
633
    public function getSessionId($sessionData, $updateLastActivity)
634
    {
635
        return $this->sessionRepository->getCurrentId($sessionData, $updateLastActivity);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
636
    }
637
638
    public function getSessionLog($uuid, $results = true)
639
    {
640
        $session = $this->sessionRepository->findByUuid($uuid);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
641
642
        return $this->logRepository->bySession($session->id, $results);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
643
    }
644
645
    public function handleThrowable($throwable)
646
    {
647
        $error_id = $this->errorRepository->findOrCreate(
648
            [
649
                'message' => $this->errorRepository->getMessageFromThrowable($throwable),
650
                'code'    => $this->errorRepository->getCodeFromThrowable($throwable),
651
            ],
652
            ['message', 'code']
653
        );
654
655
        return $this->logRepository->updateError($error_id);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
656
    }
657
658
    public function isRobot()
659
    {
660
        return $this->crawlerDetector->isRobot();
661
    }
662
663
    public function logByRouteName($name, $minutes = null)
664
    {
665
        return $this->logRepository->allByRouteName($name, $minutes);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
666
    }
667
668
    public function logEvents()
669
    {
670
        $this->eventRepository->logEvents();
671
    }
672
673
    public function logSqlQuery($query, $bindings, $time, $name)
674
    {
675
        $this->sqlQueryRepository->push([
676
            'query'    => $query,
677
            'bindings' => $bindings,
678
            'time'     => $time,
679
            'name'     => $name,
680
        ]);
681
    }
682
683
    public function pageViews($minutes, $results)
684
    {
685
        return $this->logRepository->pageViews($minutes, $results);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
686
    }
687
688
    public function pageViewsByCountry($minutes, $results)
689
    {
690
        return $this->logRepository->pageViewsByCountry($minutes, $results);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
691
    }
692
693
    public function parserIsAvailable()
694
    {
695
        return !empty($this->userAgentParser);
696
    }
697
698
    public function routeIsTrackable($route)
699
    {
700
        return $this->routeRepository->isTrackable($route);
701
    }
702
703
    public function pathIsTrackable($path)
704
    {
705
        return $this->routeRepository->pathIsTrackable($path);
706
    }
707
708
    public function setSessionData($data)
709
    {
710
        $this->sessionRepository->setSessionData($data);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
711
    }
712
713
    public function trackEvent($event)
714
    {
715
        $this->eventRepository->logEvent($event);
716
    }
717
718
    public function trackRoute($route, $request)
719
    {
720
        $this->updateRoute(
721
            $this->getRoutePathId($route, $request)
722
        );
723
    }
724
725
    public function updateRoute($route_id)
726
    {
727
        return $this->logRepository->updateRoute($route_id);
0 ignored issues
show
Bug introduced by
The property logRepository does not seem to exist. Did you mean sqlQueryLogRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
728
    }
729
730
    public function updateSessionData($data)
731
    {
732
        return $this->sessionRepository->updateSessionData($data);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
733
    }
734
735
    public function userDevices($minutes, $user_id, $results)
736
    {
737
        return $this->sessionRepository->userDevices(
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
738
            $minutes,
739
            $user_id ?: $this->authentication->getCurrentUserId(),
740
            $results
741
        );
742
    }
743
744
    public function users($minutes, $results)
745
    {
746
        return $this->sessionRepository->users($minutes, $results);
0 ignored issues
show
Bug introduced by
The property sessionRepository does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
747
    }
748
}
749