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

ProcessTask::getMissingDependencyMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
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