RangeCondition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 10
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A execute() 0 12 3

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
 * NextFlow (http://github.com/nextflow)
4
 *
5
 * @link http://github.com/nextflow/nextflow-php for the canonical source repository
6
 * @copyright Copyright (c) 2014-2016 NextFlow (http://github.com/nextflow)
7
 * @license https://raw.github.com/nextflow/nextflow-php/master/LICENSE MIT
8
 */
9
10
namespace NextFlow\Core\Condition;
11
12
use NextFlow\Core\Action\AbstractAction;
13
14
/**
15
 * A condition that checks if a value is within a range.
16
 */
17
final class RangeCondition extends AbstractAction
18
{
19
    /** The socket that is activated when the result is true. */
20
    const SOCKET_TRUE = 'true';
21
22
    /** The socket that is activated when the result is false. */
23
    const SOCKET_FALSE = 'false';
24
25
    /** The socket for the minimum value variable. */
26
    const SOCKET_MIN = 'minimum';
27
28
    /** The socket for the maximum value variable. */
29
    const SOCKET_MAX = 'maximum';
30
31
    /** The socket for the value that should be compared.. */
32
    const SOCKET_VALUE = 'value';
33
34
    /**
35
     * Initializes a new instance of this class.
36
     */
37 View Code Duplication
    public function __construct()
38
    {
39
        parent::__construct();
40
41
        $this->createSocket(self::SOCKET_TRUE);
42
        $this->createSocket(self::SOCKET_FALSE);
43
        $this->createSocket(self::SOCKET_MIN);
44
        $this->createSocket(self::SOCKET_MAX);
45
        $this->createSocket(self::SOCKET_VALUE);
46
    }
47
48
    /**
49
     * Executes the node's logic.
50
     */
51
    public function execute()
52
    {
53
        $minVal = $this->getSocket(self::SOCKET_MIN)->getNode(0)->getValue();
54
        $maxVal = $this->getSocket(self::SOCKET_MAX)->getNode(0)->getValue();
55
        $value = $this->getSocket(self::SOCKET_VALUE)->getNode(0)->getValue();
56
57
        if ($value >= $minVal && $value <= $maxVal) {
58
            $this->activate(self::SOCKET_TRUE);
59
        } else {
60
            $this->activate(self::SOCKET_FALSE);
61
        }
62
    }
63
}
64