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

Job   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 11
Bugs 1 Features 1
Metric Value
wmc 6
eloc 24
c 11
b 1
f 1
dl 0
loc 58
ccs 18
cts 20
cp 0.9
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getOutput() 0 3 1
A getResult() 0 3 1
A getCallback() 0 3 1
A execute() 0 11 2
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