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

IfTrueElement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

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 31
loc 31
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A execute() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
class IfTrueElement implements PipelineElement
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * @var Specification
22
     */
23
    private $specification;
24
25
    /**
26
     * @var PipelineElement
27
     */
28
    private $element;
29
30 8
    public function __construct(Specification $condition, PipelineElement $ifTrueElement)
31
    {
32 8
        $this->specification = $condition;
33 8
        $this->element = $ifTrueElement;
34 8
    }
35
36
    /**
37
     * @param \Alchemy\Resource\Resource $resource
38
     * @return \Alchemy\Resource\Resource
39
     */
40 8
    public function execute(Resource $resource)
41
    {
42 8
        if ($this->specification->isSatisfiedBy($resource)) {
43 4
            $resource = $this->element->execute($resource);
44 3
        }
45
46 8
        return $resource;
47
    }
48
}
49