EchoAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A execute() 11 11 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\Php\Action;
11
12
use NextFlow\Core\Action\AbstractAction;
13
14
/**
15
 * An action that simply echo's data.
16
 */
17 View Code Duplication
final class EchoAction extends AbstractAction
18
{
19
    /** The constant that defines the output socket. */
20
    const SOCKET_OUTPUT = 'out';
21
22
    /** The socket that holds the data variable. */
23
    const SOCKET_DATA = 'data';
24
25
    /**
26
     * Initializes a new instance of this class.
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
32
        $this->createSocket(self::SOCKET_OUTPUT);
33
        $this->createSocket(self::SOCKET_DATA);
34
    }
35
36
    /**
37
     * Executes the node's logic.
38
     */
39
    public function execute()
40
    {
41
        $node = $this->getSocket(self::SOCKET_DATA)->getNode(0);
42
        if ($node === null || $node->getValue() === null) {
43
            throw new \InvalidArgumentException('There is no data set.');
44
        }
45
46
        echo $node->getValue();
47
48
        $this->activate(self::SOCKET_OUTPUT);
49
    }
50
}
51