ConsoleBufferedOutput::fetch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
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 9
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
final class ConsoleBufferedOutput extends ConsoleOutput
10
{
11
    private string $buffer = '';
12
13
    /**
14
     * Returns buffer content optionally clearing it.
15
     */
16 4
    public function fetch(bool $clearBuffer = false): string
17
    {
18 4
        $content = $this->buffer;
19
20 4
        if ($clearBuffer) {
21 1
            $this->buffer = '';
22
        }
23
24 4
        return $content;
25
    }
26
27 2
    protected function doWrite(string $message, bool $newline): void
28
    {
29 2
        $this->buffer .= $message;
30
31 2
        if ($newline) {
32 1
            $this->buffer .= PHP_EOL;
33
        }
34
35 2
        parent::doWrite($message, $newline);
36
    }
37
}
38