BufferedOutput::fetch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
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