Passed
Pull Request — master (#95)
by Wilmer
02:57
created

ConsoleBufferedOutput::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Console\Output;
6
7
use Symfony\Component\Console\Output\ConsoleOutput;
8
9
/**
10
 * @author Jean-François Simon <[email protected]>
11
 */
12
class ConsoleBufferedOutput extends ConsoleOutput
13
{
14
    private string $buffer = '';
15
16
    /**
17
     * Returns buffer content optionally clearing it.
18
     *
19
     * @param bool $clearBuffer
20
     *
21
     * @return string
22
     */
23 4
    public function fetch(bool $clearBuffer = false): string
24
    {
25 4
        $content = $this->buffer;
26 4
        if ($clearBuffer) {
27 1
            $this->buffer = '';
28
        }
29
30 4
        return $content;
31
    }
32
33 2
    protected function doWrite(string $message, bool $newline): void
34
    {
35 2
        $this->buffer .= $message;
36
37 2
        if ($newline) {
38 1
            $this->buffer .= PHP_EOL;
39
        }
40
41 2
        parent::doWrite($message, $newline);
42 2
    }
43
}
44