Passed
Pull Request — master (#8)
by Kevin
15:51
created

ProcessTaskRunner::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Schedule\Task\Runner;
4
5
use Zenstruck\ScheduleBundle\Schedule\Task;
6
use Zenstruck\ScheduleBundle\Schedule\Task\ProcessTask;
7
use Zenstruck\ScheduleBundle\Schedule\Task\Result;
8
use Zenstruck\ScheduleBundle\Schedule\Task\TaskRunner;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class ProcessTaskRunner implements TaskRunner
14
{
15
    /**
16
     * @param ProcessTask|Task $task
17
     */
18
    public function __invoke(Task $task): Result
19
    {
20
        $process = clone $task->getProcess();
0 ignored issues
show
Bug introduced by
The method getProcess() does not exist on Zenstruck\ScheduleBundle\Schedule\Task. It seems like you code against a sub-type of Zenstruck\ScheduleBundle\Schedule\Task such as Zenstruck\ScheduleBundle\Schedule\Task\ProcessTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $process = clone $task->/** @scrutinizer ignore-call */ getProcess();
Loading history...
21
22
        $process->run();
23
24
        if ($process->isSuccessful()) {
25
            return Result::successful($task, $process->getOutput());
26
        }
27
28
        return Result::failure(
29
            $task,
30
            "Exit {$process->getExitCode()}: {$process->getExitCodeText()}",
31
            $process->getErrorOutput()
32
        );
33
    }
34
35
    public function supports(Task $task): bool
36
    {
37
        return $task instanceof ProcessTask;
38
    }
39
}
40