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

ProcessTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 34
ccs 11
cts 13
cp 0.8462
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getContext() 0 5 1
A getProcess() 0 3 1
A __construct() 0 9 2
A getMissingDependencyMessage() 0 3 1
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