Passed
Pull Request — 1.x (#13)
by
unknown
41:33 queued 26:35
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 4
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 const PARENT_NAME = 0;
10
    private const CHILDREN_NAME = 1;
11
    private const RELATION_NAME = 2;
12
    private const NODE = 3;
13
14
    private const BLOCK = '%s %s %s : %s';
15
16
    private array $arrows = [];
17
18
    public function addArrow(string $parent, string $children, string $relation, string $node): void
19
    {
20
        $this->arrows[] = [$parent, $children, $relation, $node];
21
    }
22
23
    public function __toString(): string
24
    {
25
        $arrows = [];
26
27
        foreach ($this->arrows as $arrow) {
28
            $arrows[] = \sprintf(
29
                self::BLOCK,
30
                $arrow[self::PARENT_NAME],
31
                $arrow[self::NODE],
32
                $arrow[self::CHILDREN_NAME],
33
                $arrow[self::RELATION_NAME]
34
            );
35
        }
36
37
        return \implode("\n", $arrows);
38
    }
39
}
40