Passed
Pull Request — 1.x (#13)
by
unknown
12:35
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
15
    private string $children;
16
17
    private string $comment;
18
19
    private string $arrow;
20
    private bool $isNullable;
21
22
    public function __construct(
23
        string $parent,
24
        string $children,
25
        string $comment,
26
        string $arrow,
27
        bool $isNullable
28
    ) {
29
        $this->parent = $this->resolveString($parent);
30
        $this->children = $this->resolveString($children);
31
        $this->comment = $comment;
32
        $this->arrow = $arrow;
33
        $this->isNullable = $isNullable;
34
    }
35
36
    public function __toString(): string
37
    {
38
        if ($this->isNullable) {
39
            $this->arrow = $this->arrow . ' "nullable"';
40
        }
41
42
        return \sprintf(self::BLOCK, $this->parent, $this->arrow, $this->children, $this->comment);
43
    }
44
}
45