LogSchedule   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A command() 0 14 3
A exec() 0 10 2
1
<?php
2
3
namespace PendoNL\LaravelScheduleLogger\Console\Scheduling;
4
5
use Illuminate\Console\Scheduling\Schedule;
6
use Illuminate\Container\Container;
7
use Symfony\Component\Process\PhpExecutableFinder;
8
use Symfony\Component\Process\ProcessUtils;
9
10
class LogSchedule extends Schedule
11
{
12
    private $rawCommand;
13
14
    /**
15
     * Add a new Artisan command event to the schedule.
16
     *
17
     * @param string $command
18
     * @param array  $parameters
19
     *
20
     * @return \Illuminate\Console\Scheduling\Event
21
     */
22
    public function command($command, array $parameters = [])
23
    {
24
        $this->rawCommand = $command;
25
26
        if (class_exists($command)) {
27
            $command = Container::getInstance()->make($command)->getName();
28
        }
29
30
        $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
31
32
        $artisan = defined('ARTISAN_BINARY') ? ProcessUtils::escapeArgument(ARTISAN_BINARY) : 'artisan';
33
34
        return $this->exec("{$binary} {$artisan} {$command}", $parameters);
35
    }
36
37
    /**
38
     * Add a new command event to the schedule.
39
     *
40
     * @param string $command
41
     * @param array  $parameters
42
     *
43
     * @return \Illuminate\Console\Scheduling\Event
44
     */
45
    public function exec($command, array $parameters = [])
46
    {
47
        if (count($parameters)) {
48
            $command .= ' '.$this->compileParameters($parameters);
49
        }
50
51
        $this->events[] = $event = new LogEvent($this->mutex, $command, $this->rawCommand);
52
53
        return $event;
54
    }
55
}
56