Passed
Pull Request — 1.x (#13)
by
unknown
43:32 queued 28:34
created

Relation::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
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