ClearAction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
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\Arrays\Action;
11
12
use NextFlow\Core\Action\AbstractAction;
13
14
/**
15
 * Clears an array.
16
 */
17
final class ClearAction extends AbstractAction
18
{
19
    /** The output action socket. */
20
    const SOCKET_OUTPUT = 'out';
21
22
    /** The array variable socket. */
23
    const SOCKET_ARRAY = 'array';
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_ARRAY);
34
    }
35
36
    /**
37
     * Executes the node's logic.
38
     */
39
    public function execute()
40
    {
41
        $array = $this->getSocket(self::SOCKET_ARRAY)->getNode(0);
42
        if ($array === null) {
43
            throw new \InvalidArgumentException('No array variable provided.');
44
        }
45
46
        $array->setValue(array());
47
48
        $this->activate(self::SOCKET_OUTPUT);
49
    }
50
}
51