Passed
Push — 1.x ( a9995e...5c2b79 )
by Aleksei
12:31
created

Relation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\MermaidRenderer;
6
7
class Relation implements Stringable
8
{
9
    use StringFormatter;
10
11
    private const BLOCK = '%s %s %s : %s';
12
13
    private string $parent;
14
    private string $children;
15
    private string $comment;
16
    private string $arrow;
17
    private bool $isNullable;
18
19
    public function __construct(
20
        string $parent,
21
        string $children,
22
        string $comment,
23
        string $arrow,
24
        bool $isNullable
25
    ) {
26
        $this->parent = $this->resolveString($parent);
27
        $this->children = $this->resolveString($children);
28
        $this->comment = $comment;
29
        $this->arrow = $arrow;
30
        $this->isNullable = $isNullable;
31
    }
32
33
    public function __toString(): string
34
    {
35
        if ($this->isNullable) {
36
            $this->arrow = $this->arrow . ' "nullable"';
37
        }
38
39
        return \sprintf(self::BLOCK, $this->parent, $this->arrow, $this->children, $this->comment);
40
    }
41
}
42