BufferedOutput   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 31
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isInteractive() 0 3 1
A write() 0 3 1
A __toString() 0 3 1
A fetch() 0 9 2
1
<?php
2
3
namespace PhpSchool\Terminal\IO;
4
5
/**
6
 * @author Aydin Hassan <[email protected]>
7
 */
8
class BufferedOutput implements OutputStream
9
{
10
    private $buffer = '';
11
12
    public function write(string $buffer): void
13
    {
14
        $this->buffer .= $buffer;
15
    }
16
17
    public function fetch(bool $clean = true) : string
18
    {
19
        $buffer = $this->buffer;
20
21
        if ($clean) {
22
            $this->buffer = '';
23
        }
24
25
        return $buffer;
26
    }
27
28
    public function __toString() : string
29
    {
30
        return $this->fetch();
31
    }
32
33
    /**
34
     * Whether the stream is connected to an interactive terminal
35
     */
36
    public function isInteractive() : bool
37
    {
38
        return false;
39
    }
40
}
41