Passed
Pull Request — 1.x (#12)
by
unknown
12:15
created

EntityTable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
c 1
b 0
f 0
dl 0
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addRow() 0 3 1
A __construct() 0 3 1
A addMethod() 0 5 1
A __toString() 0 11 2
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
    private const BLOCK = <<<BLOCK
13
        class %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 addMethod(string $name, string ...$params): void
32
    {
33
        $row = sprintf('%s(%s)', $name, implode('', $params));
34
35
        $this->rows[] = [$row];
36
    }
37
38
    public function __toString(): string
39
    {
40
        $rows = [];
41
42
        foreach ($this->rows as $row) {
43
            $rows[] = implode(self::SEPARATOR, $row);
44
        }
45
46
        $body = implode("\n" . self::INDENT, $rows);
47
48
        return sprintf(self::BLOCK, $this->title, $body);
49
    }
50
}
51