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

EntityArrow::addArrow()   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 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\MermaidRenderer\Entity;
6
7
final class EntityArrow implements EntityInterface
8
{
9
    private string $title;
10
    private array $arrows = [];
11
12
    public const BLOCK = '%s %s %s : %s';
13
    public const NOT_NULLABLE = '||--|{';
14
    public const NULLABLE = '||--o{';
15
16
    public function __construct(string $title)
17
    {
18
        $this->title = $title;
19
    }
20
21
    public function addArrow(string $children, string $relation, bool $isNullable = false): void
22
    {
23
        $this->arrows[] = [$children, $relation, $isNullable];
24
    }
25
26
    public function toString(): string
27
    {
28
        $arrows = [];
29
30
        foreach ($this->arrows as $arrow) {
31
            $arrows[] = sprintf(
32
                self::BLOCK,
33
                $this->title,
34
                $arrow[2] ? self::NULLABLE : self::NOT_NULLABLE,
35
                $arrow[0],
36
                $arrow[1]
37
            );
38
        }
39
40
        return implode("\n", $arrows);
41
    }
42
}
43