IfCondition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 19.64 %

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 11
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A execute() 0 17 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 compares two values with each other.
16
 */
17
final class IfCondition extends AbstractAction
18
{
19
    /** The output socket that is activated when the values are equal. */
20
    const SOCKET_EQUAL = 'equal';
21
22
    /** The output socket that is activated when the values are not equal. */
23
    const SOCKET_NOT_EQUAL = 'not-equal';
24
25
    /** The output socket that is activated when the left value is less than the right value. */
26
    const SOCKET_LESS_THAN = 'less-than';
27
28
    /** The output socket that is activated when the left value is greater than the right value. */
29
    const SOCKET_GREATER_THAN = 'greater-than';
30
31
    /** The left value to compare. */
32
    const SOCKET_VALUELFT = 'value-lft';
33
34
    /** The right value to compare. */
35
    const SOCKET_VALUERGT = 'value-rgt';
36
37
    /**
38
     * Initializes a new instance of this class.
39
     */
40 View Code Duplication
    public function __construct()
41
    {
42
        parent::__construct();
43
44
        $this->createSocket(self::SOCKET_EQUAL);
45
        $this->createSocket(self::SOCKET_NOT_EQUAL);
46
        $this->createSocket(self::SOCKET_LESS_THAN);
47
        $this->createSocket(self::SOCKET_GREATER_THAN);
48
        $this->createSocket(self::SOCKET_VALUELFT);
49
        $this->createSocket(self::SOCKET_VALUERGT);
50
    }
51
52
    /**
53
     * Executes the node's logic.
54
     */
55
    public function execute()
56
    {
57
        $valueLft = $this->getSocket(self::SOCKET_VALUELFT)->getNode(0)->getValue();
58
        $valueRgt = $this->getSocket(self::SOCKET_VALUERGT)->getNode(0)->getValue();
59
60
        if ($valueLft === $valueRgt) {
61
            $this->activate(self::SOCKET_EQUAL);
62
        } else {
63
            if ($valueLft < $valueRgt) {
64
                $this->activate(self::SOCKET_LESS_THAN);
65
            } else {
66
                $this->activate(self::SOCKET_GREATER_THAN);
67
            }
68
69
            $this->activate(self::SOCKET_NOT_EQUAL);
70
        }
71
    }
72
}
73