Passed
Push — master ( 76636e...a7cce5 )
by Kevin
03:12
created

ProcessTask::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Task;
4
5
use Symfony\Component\Process\Process;
6
use Zenstruck\ScheduleBundle\Schedule\HasMissingDependencyMessage;
7
use Zenstruck\ScheduleBundle\Schedule\Task;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class ProcessTask extends Task implements HasMissingDependencyMessage
13
{
14
    private $process;
15
16
    /**
17
     * @param string|Process $process
18
     */
19 11
    public function __construct($process)
20
    {
21 11
        if (!$process instanceof Process) {
22 11
            $process = Process::fromShellCommandline($process);
23
        }
24
25 11
        $this->process = $process;
26
27 11
        parent::__construct($process->getCommandLine());
28 11
    }
29
30 2
    public function getProcess(): Process
31
    {
32 2
        return $this->process;
33
    }
34
35 1
    public function getContext(): array
36
    {
37
        return [
38 1
            'Command Line' => $this->process->getCommandLine(),
39 1
            'Command Timeout' => $this->process->getTimeout(),
40
        ];
41
    }
42
43
    public static function getMissingDependencyMessage(): string
44
    {
45
        return \sprintf('"symfony/process" is required to use "%s". Install with "composer require symfony/process".', self::class);
46
    }
47
}
48