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

BufferedOutput   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 4 1
A fetch() 0 10 2
A __toString() 0 4 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