• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JBZoo / Mermaid-PHP / 7634240466

21 Jan 2024 10:26PM UTC coverage: 89.693%. Remained the same
7634240466

push

github

web-flow
Fixed code style (#18)

1 of 2 new or added lines in 1 file covered. (50.0%)

7 existing lines in 2 files now uncovered.

409 of 456 relevant lines covered (89.69%)

34.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/src/ClassDiagram/Relationship/Relationship.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Mermaid-PHP.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Mermaid-PHP
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\MermaidPHP\ClassDiagram\Relationship;
18

19
use JBZoo\MermaidPHP\ClassDiagram\Concept\Concept;
20

21
class Relationship
22
{
23
    public function __construct(
24
        protected Concept $classA,
25
        protected Concept $classB,
26
        protected RelationType $relationType,
27
        protected ?string $label = null,
28
        protected null|Cardinality|string $cardinalityA = null,
29
        protected null|Cardinality|string $cardinalityB = null,
30
        protected ?Link $link = null,
31
        protected ?RelationType $inverseRelationType = null,
32
    ) {
33
        if ($this->link === null) {
16✔
34
            $this->link = $this->relationType->getDefaultLink();
16✔
35
        }
36
    }
37

38
    public function __toString(): string
39
    {
40
        $result = \sprintf(
16✔
41
            '%s%s %s%s %s',
8✔
42
            $this->classA->getId(),
16✔
43
            self::renderCardinality($this->cardinalityA),
16✔
44
            $this->renderRelation(),
16✔
45
            self::renderCardinality($this->cardinalityB),
16✔
46
            $this->classB->getId(),
16✔
47
        );
8✔
48

49
        if ($this->label !== null) {
16✔
50
            $result .= \sprintf(' : %s', $this->label);
8✔
51
        }
52

53
        return $result;
16✔
54
    }
55

56
    private function renderRelation(): string
57
    {
58
        if ($this->link === null) {
16✔
NEW
59
            return '';
×
60
        }
61

62
        return $this->relationType->renderRelation($this->link, $this->inverseRelationType);
16✔
63
    }
64

65
    private static function renderCardinality(null|Cardinality|string $cardinality): string
66
    {
67
        if ($cardinality === null) {
16✔
68
            return '';
12✔
69
        }
70

71
        $value = $cardinality instanceof Cardinality ? $cardinality->value : $cardinality;
4✔
72

73
        return \sprintf(' "%s"', $value);
4✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc