Completed
Push — master ( ef6d42...141e8d )
by Frank
02:03
created

InterruptibleProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\Pipeline;
4
5
class InterruptibleProcessor implements ProcessorInterface
6
{
7
    /**
8
     * @var callable
9
     */
10
    private $check;
11
12
    /**
13
     * InterruptibleProcessor constructor.
14
     *
15
     * @param callable $check
16
     */
17 4
    public function __construct(callable $check)
18
    {
19 4
        $this->check = $check;
20 4
    }
21
22
    /**
23
     * @param array $stages
24
     * @param mixed $payload
25
     *
26
     * @return mixed
27
     */
28 2
    public function process(array $stages, $payload)
29
    {
30 2
        $check = $this->check;
31
32 2
        foreach ($stages as $stage) {
33 2
            $payload = $stage($payload);
34
35 2
            if ($check($payload) !== true) {
36 2
                return $payload;
37
            }
38 2
        }
39
40 2
        return $payload;
41
    }
42
}
43