Completed
Push — master ( 2e5bdd...9e2471 )
by Ryuichi
05:26
created

ConsoleOutputStream::write()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 14
cp 0
rs 8.2222
c 0
b 0
f 0
cc 7
crap 56
eloc 11
nc 4
nop 3
1
<?php
2
namespace WebStream\IO;
3
4
/**
5
 * ConsoleOutputStream
6
 * @author Ryuichi TANAKA.
7
 * @since 2016/02/27
8
 * @version 0.7
9
 */
10
class ConsoleOutputStream extends OutputStream
11
{
12
    /**
13
     * constructor
14
     */
15
    public function __construct()
16
    {
17
        parent::__construct("");
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function write($buf, int $off = null, int $len = null)
24
    {
25
        $data = null;
26
        if ($off === null && $len === null) {
27
            $data = $buf;
28
        } elseif ($off !== null && $len === null) {
29
            $data = substr($buf, $off);
30
        } elseif ($off === null && $len !== null) {
31
            $data = substr($buf, 0, $len);
32
        } else {
33
            $data = substr($buf, $off, $len);
34
        }
35
36
        $this->stream .= $data;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function close()
43
    {
44
        $this->stream = null;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function flush()
51
    {
52
        echo $this->stream;
53
    }
54
}
55