ReadableFifo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 42
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A read() 0 13 3
A write() 0 4 1
A getStream() 0 6 1
1
<?php
2
/**
3
 * Process Library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\Process\Pipe;
7
8
use Slince\Process\Exception\RuntimeException;
9
10
class ReadableFifo extends AbstractFifo
11
{
12
    public function __construct($pathname, $blocking = true, $mode = 'r+', $permission = 0666)
13
    {
14
        parent::__construct($pathname, $blocking, $mode, $permission);
15
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function read()
21
    {
22
        $stream = $this->getStream();
23
        if ($this->blocking) {
24
            $read = [$stream];
25
            $write = [];
26
            $except = [];
27
            if (stream_select($read, $write, $except, null) > 0) {
28
                return stream_get_contents($stream);
29
            }
30
        }
31
        return stream_get_contents($stream);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function write($message)
38
    {
39
        throw new RuntimeException("Cannot write some data to an write-only fifo");
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getStream()
46
    {
47
        $stream = parent::getStream();
48
        stream_set_blocking($stream, false);
49
        return $stream;
50
    }
51
}
52