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

ConsoleBufferedOutput   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 10
c 1
b 0
f 1
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 8 2
A doWrite() 0 9 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