LineWriter::line()   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
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Squareetlabs\LaravelToon\Toon;
6
7
class LineWriter
8
{
9
    private array $lines = [];
10
    private int $indent = 0;
11
12
    public function __construct(
13
        private readonly int $indentSize = 2,
14
    ) {}
15
16
    public function line(string $content = ''): void
17
    {
18
        $indentation = str_repeat(' ', $this->indent * $this->indentSize);
19
        $this->lines[] = $indentation.$content;
20
    }
21
22
    public function indent(): void
23
    {
24
        ++$this->indent;
25
    }
26
27
    public function dedent(): void
28
    {
29
        if ($this->indent > 0) {
30
            --$this->indent;
31
        }
32
    }
33
34
    public function getContent(): string
35
    {
36
        return implode("\n", $this->lines);
37
    }
38
39
    public function getLines(): array
40
    {
41
        return $this->lines;
42
    }
43
}
44
45