WritableFifo   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 44
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A read() 0 4 1
A write() 0 5 1
A getStream() 0 8 2
A setBlocking() 0 7 2
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 WritableFifo extends AbstractFifo
11
{
12
    public function __construct($pathname, $blocking = true, $mode = 'w+', $permission = 0666)
13
    {
14
        parent::__construct($pathname, $blocking, $mode, $permission);
15
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function read()
21
    {
22
        throw new RuntimeException("Cannot read data from an write-only fifo");
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function write($message)
29
    {
30
        $stream = $this->getStream();
31
        return fwrite($stream, $message, strlen($message));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getStream()
38
    {
39
        $stream = parent::getStream();
40
        if ($this->blocking === false) {
41
            stream_set_blocking($stream, false);
42
        }
43
        return $stream;
44
    }
45
46
    public function setBlocking($blocking)
47
    {
48
        parent::setBlocking($blocking);
49
        if (!is_null($this->stream)) {
50
            stream_set_blocking($this->stream, $blocking);
51
        }
52
    }
53
}
54