ChainDecision   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConditions() 0 9 2
A __construct() 0 3 1
A isApplied() 0 9 3
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Vacancy\Decision;
17
18
use Veslo\AnthillBundle\Vacancy\DecisionInterface;
19
20
/**
21
 * Will be applied whenever all nested decisions becomes applied
22
 */
23
class ChainDecision implements DecisionInterface
24
{
25
    /**
26
     * Nested decisions
27
     *
28
     * @var DecisionInterface[]
29
     */
30
    private $decisions;
31
32
    /**
33
     * NotADuplicate constructor.
34
     *
35
     * @param DecisionInterface[] $decisions Nested decisions
36
     */
37
    public function __construct(array $decisions)
38
    {
39
        $this->decisions = $decisions;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function isApplied(object $context): bool
46
    {
47
        foreach ($this->decisions as $decision) {
48
            if (!$decision->isApplied($context)) {
49
                return false;
50
            }
51
        }
52
53
        return true;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getConditions(): iterable
60
    {
61
        $conditions = [];
62
63
        foreach ($this->decisions as $decision) {
64
            $conditions = array_merge($conditions, $decision->getConditions());
0 ignored issues
show
Bug introduced by
$decision->getConditions() of type iterable is incompatible with the type array expected by parameter $arrays of array_merge(). ( Ignorable by Annotation )

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

64
            $conditions = array_merge($conditions, /** @scrutinizer ignore-type */ $decision->getConditions());
Loading history...
65
        }
66
67
        return $conditions;
68
    }
69
}
70