ProcessTask::__construct()   A
last analyzed

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
    /** @var Process */
15
    private $process;
16
17
    /**
18
     * @param string|Process $process
19 11
     */
20
    public function __construct($process)
21 11
    {
22 11
        if (!$process instanceof Process) {
23
            $process = Process::fromShellCommandline($process);
24
        }
25 11
26
        $this->process = $process;
27 11
28 11
        parent::__construct($process->getCommandLine());
29
    }
30 2
31
    public function getProcess(): Process
32 2
    {
33
        return $this->process;
34
    }
35 1
36
    public function getContext(): array
37
    {
38 1
        return [
39 1
            'Command Line' => $this->process->getCommandLine(),
40
            'Command Timeout' => (string) $this->process->getTimeout(),
41
        ];
42
    }
43
44
    public static function getMissingDependencyMessage(): string
45
    {
46
        return \sprintf('"symfony/process" is required to use "%s". Install with "composer require symfony/process".', self::class);
47
    }
48
}
49