LogEvent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace PendoNL\LaravelScheduleLogger\Console\Scheduling;
4
5
use Illuminate\Console\Scheduling\Event;
6
use Illuminate\Console\Scheduling\Mutex;
7
8
class LogEvent extends Event
9
{
10
    /**
11
     * Create a new event instance.
12
     *
13
     * @param string $command
14
     * @param string $rawCommand
15
     */
16
    public function __construct(Mutex $mutex, $command, $rawCommand)
17
    {
18
        parent::__construct($mutex, $command);
19
20
        $this->mutex = $mutex;
21
        $this->command = $command;
22
        $this->output = $this->getDefaultOutput();
23
24
        $this->registerScheduleLogger($rawCommand);
25
    }
26
27
    /**
28
     * Add the logger functions to the before and
29
     * after calls of the event.
30
     */
31
    public function registerScheduleLogger($command)
32
    {
33
        $this->before(function () use ($command) {
34
            app()->make('laravel-schedulelogger')->start($command);
35
        });
36
37
        $this->after(function () use ($command) {
38
            app()->make('laravel-schedulelogger')->end($command);
39
        });
40
    }
41
}
42