RouteEventSubscriber::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace Arcanedev\LaravelTracker\EventListeners;
2
3
use Arcanedev\LaravelTracker\Contracts\Tracker;
4
use Illuminate\Routing\Events\RouteMatched;
5
use Illuminate\Routing\Route;
6
7
/**
8
 * Class     RouteEventSubscriber
9
 *
10
 * @package  Arcanedev\LaravelTracker\EventListeners
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class RouteEventSubscriber
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
20
    /** @var \Arcanedev\LaravelTracker\Contracts\Tracker */
21
    private $tracker;
22
23
    /* -----------------------------------------------------------------
24
     |  Constructor
25
     | -----------------------------------------------------------------
26
     */
27
28
    /**
29
     * RouteEventSubscriber constructor.
30
     *
31
     * @param  \Arcanedev\LaravelTracker\Contracts\Tracker  $manager
32
     */
33 117
    public function __construct(Tracker $manager)
34
    {
35 117
        $this->tracker = $manager;
36 117
    }
37
38
    /* -----------------------------------------------------------------
39
     |  Main Methods
40
     | -----------------------------------------------------------------
41
     */
42
43
    /**
44
     * Register the listeners for the subscriber.
45
     *
46
     * @param  \Illuminate\Events\Dispatcher  $events
47
     */
48 117
    public function subscribe($events)
49
    {
50 117
        $class = self::class;
51
52 117
        $events->listen(RouteMatched::class, "$class@handle");
53 117
    }
54
55
    /**
56
     * Track the matched route.
57
     *
58
     * @param  \Illuminate\Routing\Events\RouteMatched  $event
59
     */
60 6
    public function handle(RouteMatched $event)
61
    {
62 6
        $this->tracker->trackMatchedRoute($event->route, $event->request);
63 6
    }
64
}
65