LineWriter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getContent() 0 3 1
A getLines() 0 3 1
A line() 0 4 1
A indent() 0 3 1
A dedent() 0 4 2
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