ChainExitStrategy   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 46
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A addExitStrategy() 0 4 1
A shouldExit() 0 12 3
A getReason() 0 4 1
1
<?php
2
3
namespace Zenstruck\Queue\Subscriber\ExitStrategy;
4
5
use Zenstruck\Queue\Subscriber\ExitStrategy;
6
7
/**
8
 * @author Kevin Bond <[email protected]>
9
 */
10
class ChainExitStrategy implements ExitStrategy
11
{
12
    private $reason;
13
14
    /** @var array|ExitStrategy[] */
15
    private $exitStrategies = [];
16
17
    /**
18
     * @param array|ExitStrategy[] $exitStrategies
19
     */
20 9
    public function __construct(array $exitStrategies = [])
21
    {
22 9
        foreach ($exitStrategies as $exitStrategy) {
23 4
            $this->addExitStrategy($exitStrategy);
24 9
        }
25 9
    }
26
27 8
    public function addExitStrategy(ExitStrategy $exitStrategy)
28
    {
29 8
        $this->exitStrategies[] = $exitStrategy;
30 8
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 7
    public function shouldExit($count)
36
    {
37 7
        foreach ($this->exitStrategies as $exitStrategy) {
38 7
            if ($exitStrategy->shouldExit($count)) {
39 6
                $this->reason = $exitStrategy->getReason();
40
41 6
                return true;
42
            }
43 4
        }
44
45 1
        return false;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 6
    public function getReason()
52
    {
53 6
        return $this->reason;
54
    }
55
}
56