Passed
Push — master ( 18c542...46352d )
by Kevin
02:34
created

MockTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
c 0
b 0
f 0
dl 0
loc 36
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 3 1
A exception() 0 6 1
A failure() 0 6 1
A success() 0 6 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Tests\Fixture;
4
5
use Zenstruck\ScheduleBundle\Schedule\Task;
6
use Zenstruck\ScheduleBundle\Schedule\Task\Result;
7
use Zenstruck\ScheduleBundle\Schedule\Task\SelfRunningTask;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class MockTask extends Task implements SelfRunningTask
13
{
14
    private $result;
15
16
    public function __construct(string $description = 'my task')
17
    {
18
        parent::__construct($description);
19
    }
20
21
    public function __invoke(): Result
22
    {
23
        return $this->result;
24
    }
25
26
    public static function success(string $name = 'my task', string $output = null): self
27
    {
28
        $task = new self($name);
29
        $task->result = Result::successful($task, $output);
30
31
        return $task;
32
    }
33
34
    public static function failure(string $description = 'failure description', string $name = 'my task', string $output = null): self
35
    {
36
        $task = new self($name);
37
        $task->result = Result::failure($task, $description, $output);
38
39
        return $task;
40
    }
41
42
    public static function exception(\Throwable $e, string $name = 'my task', string $output = null): self
43
    {
44
        $task = new self($name);
45
        $task->result = Result::exception($task, $e, $output);
46
47
        return $task;
48
    }
49
}
50