ConsoleOutputStream   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 43
ccs 15
cts 15
cp 1
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A close() 0 3 1
A flush() 0 3 1
A __construct() 0 3 1
B write() 0 14 7
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