ProcessTask   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
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 35
ccs 11
cts 13
cp 0.8462
rs 10

4 Methods

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