Passed
Pull Request — 1.x (#12)
by
unknown
29:27 queued 14:24
created

EntityTable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\MermaidRenderer\Entity;
6
7
final class EntityTable implements EntityInterface
8
{
9
    private string $title;
10
    private array $rows = [];
11
12
    public const BLOCK = <<<BLOCK
13
        %s {
14
            %s
15
        }
16
        BLOCK;
17
18
    public const INDENT = '    ';
19
    public const SEPARATOR = ' ';
20
21
    public function __construct(string $title)
22
    {
23
        $this->title = $title;
24
    }
25
26
    public function addRow(string ...$values): void
27
    {
28
        $this->rows[] = $values;
29
    }
30
31
    public function toString(): string
32
    {
33
        $rows = [];
34
35
        foreach ($this->rows as $row) {
36
            $rows[] = implode(self::SEPARATOR, $row);
37
        }
38
39
        $body = implode("\n" . self::INDENT, $rows);
40
41
        return sprintf(self::BLOCK, $this->title, $body);
42
    }
43
}
44