StringBuffer::flush()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Output;
6
7
use AlecRabbit\Spinner\Core\Output\Contract\IBuffer;
8
use Generator;
9
10
use function is_iterable;
11
12
final class StringBuffer implements IBuffer
13
{
14
    public function __construct(
15
        protected string $buffer = '',
16
    ) {
17
    }
18
19
    public function flush(): Generator
20
    {
21
        yield $this->buffer;
22
        $this->buffer = '';
23
    }
24
25
    public function append(iterable|string $message): IBuffer
26
    {
27
        if (!is_iterable($message)) {
28
            $message = [$message];
29
        }
30
        /** @var string $item */
31
        foreach ($message as $item) {
32
            $this->buffer .= $item;
33
        }
34
        return $this;
35
    }
36
}
37