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

IfThenElseElement::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
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