CallbackAction::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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 invokes a callback.
16
 */
17
final class CallbackAction extends AbstractAction
18
{
19
    /** The constant that defines the output socket. */
20
    const SOCKET_OUTPUT = 'out';
21
22
    /**
23
     * The callback that should be invoked.
24
     *
25
     * @var callable
26
     */
27
    private $callback;
28
29
    /**
30
     * Initializes a new instance of this class.
31
     *
32
     * @param callable $callback The callback.
33
     */
34
    public function __construct($callback)
35
    {
36
        parent::__construct();
37
38
        if (!is_callable($callback)) {
39
            throw new \InvalidArgumentException('The provided callback is not callable.');
40
        }
41
42
        $this->callback = $callback;
43
44
        $this->createSocket(self::SOCKET_OUTPUT);
45
    }
46
47
    /**
48
     * Executes the node's logic.
49
     */
50
    public function execute()
51
    {
52
        call_user_func_array($this->callback, array($this));
53
54
        $this->activate(self::SOCKET_OUTPUT);
55
    }
56
}
57