Passed
Push — master ( 5f5cdb...7b0215 )
by Jakub
01:54
created

Job::getResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MyTester;
6
7
/**
8
 * One job of the test suite
9
 *
10
 * @author Jakub Konečný
11
 * @property-read callable $callback
12
 * @property-read string $result
13
 * @property-read string $output @internal
14
 * @method void onAfterExecute()
15
 */
16
final class Job
17
{
18
    use \Nette\SmartObject;
19
20
    public readonly string $name;
21
    /** @var callable Task */
22
    protected $callback;
23
    public readonly array $params;
24
    // phpcs:ignore
25
    public readonly bool|string $skip;
26
    protected JobResult $result = JobResult::PASSED;
0 ignored issues
show
Bug introduced by
The type MyTester\JobResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
    protected string $output = "";
28
    /** @var callable[] */
29
    public array $onAfterExecute = [];
30
31 1
    public function __construct(
32
        string $name,
33
        callable $callback,
34
        array $params = [],
35
        bool|string $skip = false,
36
        array $onAfterExecute = []
37
    ) {
38 1
        $this->name = $name;
39 1
        $this->callback = $callback;
40 1
        $this->params = $params;
41 1
        $this->skip = $skip;
42 1
        $this->onAfterExecute = $onAfterExecute;
43
    }
44
45
    protected function getCallback(): callable
46
    {
47
        return $this->callback;
48
    }
49
50 1
    protected function getResult(): JobResult
51
    {
52 1
        return $this->result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->result returns the type string which is incompatible with the type-hinted return MyTester\JobResult.
Loading history...
53
    }
54
55 1
    protected function getOutput(): string
56
    {
57 1
        return $this->output;
58
    }
59
60
    /**
61
     * Executes the task
62
     */
63 1
    public function execute(): void
64
    {
65 1
        if (!$this->skip) {
66 1
            ob_start();
67 1
            call_user_func_array($this->callback, $this->params);
68 1
            $this->onAfterExecute();
69
            /** @var string $output */
70 1
            $output = ob_get_clean();
71 1
            $this->output = $output;
72
        }
73 1
        $this->result = JobResult::fromJob($this);
74
    }
75
}
76