Stage::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author: RunnerLee
4
 * @email: [email protected]
5
 * @time: 2018-12
6
 */
7
8
namespace Runner\Pipeline;
9
10
use Runner\Pipeline\Contracts\Stage as StageInterface;
11
12
class Stage implements StageInterface
13
{
14
    /**
15
     * @var callable
16
     */
17
    protected $callback;
18
19
    /**
20
     * @var Stage|null
21
     */
22
    protected $next;
23
24
    /**
25
     * Stage constructor.
26
     *
27
     * @param $callback
28
     * @param Stage|null $next
29
     */
30 1
    public function __construct($callback, self $next = null)
31
    {
32 1
        $this->callback = $callback;
33 1
        $this->next = $next;
34 1
    }
35
36
    /**
37
     * @param $payload
38
     *
39
     * @return mixed
40
     */
41 1
    public function handle($payload)
42
    {
43
        // destination callback (without next stage)
44 1
        if (is_null($this->next)) {
45 1
            return call_user_func($this->callback, $payload);
46
        }
47
48 1
        return call_user_func($this->callback, $payload, function ($payload) {
49 1
            return $this->next->handle($payload);
0 ignored issues
show
Bug introduced by
The method handle() does not exist on null. ( Ignorable by Annotation )

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

49
            return $this->next->/** @scrutinizer ignore-call */ handle($payload);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50 1
        });
51
    }
52
}
53