StreamCloseAction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 16 4
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\Stream\Action;
11
12
use InvalidArgumentException;
13
use NextFlow\Core\Action\AbstractAction;
14
15
/**
16
 * Closes a stream.
17
 */
18
final class StreamCloseAction extends AbstractAction
19
{
20
    /** The output socket. */
21
    const SOCKET_OUTPUT = 'out';
22
23
    /** The stream variable socket. */
24
    const SOCKET_STREAM = 'stream';
25
26
    /**
27
     * Initializes a new instance of this class.
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
33
        $this->createSocket(self::SOCKET_OUTPUT);
34
        $this->createSocket(self::SOCKET_STREAM);
35
    }
36
37
    /**
38
     * Executes the node's logic.
39
     */
40
    public function execute()
41
    {
42
        $socket = $this->getSocket(self::SOCKET_STREAM);
43
        if (!$socket || !$socket->hasNodes()) {
44
            throw new InvalidArgumentException('There is no stream to close.');
45
        }
46
47
        $streamValue = $socket->getNode(0)->getValue();
48
        if (!is_resource($streamValue)) {
49
            throw new InvalidArgumentException('Invalid stream provided.');
50
        }
51
52
        fclose($streamValue);
53
54
        $this->activate(self::SOCKET_OUTPUT);
55
    }
56
}
57