Completed
Pull Request — master (#80)
by Aydin
01:50
created

BufferedOutput::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace PhpSchool\CliMenu\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