SwitchCondition::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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
use NextFlow\Core\Node\NodeInterface;
14
15
/**
16
 * A condition that is able to switch between multiple values.
17
 */
18
final class SwitchCondition extends AbstractAction
19
{
20
    /** The socket that connects the value variable. */
21
    const SOCKET_VALUE = 'value';
22
23
    /**
24
     * Initializes a new instance of this class.
25
     */
26
    public function __construct()
27
    {
28
        parent::__construct();
29
30
        $this->createSocket(self::SOCKET_VALUE);
31
    }
32
33
    /**
34
     * Binds the given node to a socket.
35
     *
36
     * @param string $socket The name of the socket to bind to.
37
     * @param NodeInterface $node The node to bind to.
38
     */
39
    public function bind($socket, NodeInterface $node)
40
    {
41
        if ($socket != self::SOCKET_VALUE && !$this->hasSocket($socket)) {
42
            $this->createSocket($socket);
43
        }
44
45
        parent::bind($socket, $node);
46
    }
47
48
    /**
49
     * Executes the node's logic.
50
     */
51
    public function execute()
52
    {
53
        $value = $this->getSocket(self::SOCKET_VALUE)->getNode(0)->getValue();
54
55
        if ($this->hasSocket($value)) {
56
            $this->activate($value);
57
        }
58
    }
59
}
60