ConsoleOutputStream::flush()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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