CallbackAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A execute() 0 6 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