Completed
Push — master ( e60e0a...93839a )
by Thibaud
02:26
created

IfThenElseElement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 42
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of alchemy/pipeline-component.
5
 *
6
 * (c) Alchemy <[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
12
namespace Alchemy\Pipeline\Element;
13
14
use Alchemy\Pipeline\PipelineElement;
15
use Alchemy\Pipeline\Specification;
16
use Alchemy\Resource\Resource;
17
18
class IfThenElseElement implements PipelineElement
19
{
20
    /**
21
     * @var Specification
22
     */
23
    private $specification;
24
25
    /**
26
     * @var PipelineElement
27
     */
28
    private $element;
29
30
    /**
31
     * @var PipelineElement
32
     */
33
    private $elseElement;
34
35
    /**
36
     * @param Specification $condition
37
     * @param PipelineElement $thenElement
38
     * @param PipelineElement $elseElement
39
     */
40 8
    public function __construct(Specification $condition, PipelineElement $thenElement, PipelineElement $elseElement)
41
    {
42 8
        $this->specification = $condition;
43 8
        $this->element = $thenElement;
44 8
        $this->elseElement = $elseElement;
45 8
    }
46
47
    /**
48
     * @param \Alchemy\Resource\Resource $resource
49
     * @return \Alchemy\Resource\Resource
50
     */
51 8
    public function execute(Resource $resource)
52
    {
53 8
        if ($this->specification->isSatisfiedBy($resource)) {
54 4
            return $this->element->execute($resource);
55
        }
56
57 4
        return $this->elseElement->execute($resource);
58
    }
59
}
60