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

JBZoo / Mermaid-PHP / 29807322753

20 Jul 2026 07:54PM UTC coverage: 88.553%. Remained the same
29807322753

push

github

web-flow
Merge pull request #29 from JBZoo/release/8.0

8.0.0 — PHP 8.3+ floor & lock-step major

7 of 8 new or added lines in 1 file covered. (87.5%)

5 existing lines in 1 file now uncovered.

410 of 463 relevant lines covered (88.55%)

60.36 hits per line

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

61.29
/src/ClassDiagram/ClassDiagram.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;
18

19
use JBZoo\MermaidPHP\ClassDiagram\Concept\Concept;
20
use JBZoo\MermaidPHP\ClassDiagram\ConceptNamespace\ConceptNamespace;
21
use JBZoo\MermaidPHP\ClassDiagram\Relationship\Relationship;
22
use JBZoo\MermaidPHP\Direction;
23
use JBZoo\MermaidPHP\Helper;
24
use JBZoo\MermaidPHP\Render;
25

26
/**
27
 * @psalm-suppress ClassMustBeFinal
28
 */
29
class ClassDiagram
30
{
31
    private ?string $title        = null;
32
    private ?Direction $direction = null;
33

34
    /** @var ConceptNamespace[] */
35
    private array $namespaces = [];
36

37
    /** @var Concept[] */
38
    private array $classes = [];
39

40
    /** @var Relationship[] */
41
    private array $relationships = [];
42

43
    public function __toString(): string
44
    {
45
        return $this->render();
18✔
46
    }
47

48
    public function setTitle(string $title): self
49
    {
50
        $this->title = $title;
6✔
51

52
        return $this;
6✔
53
    }
54

55
    public function setDirection(Direction $direction): self
56
    {
57
        $this->direction = $direction;
6✔
58

59
        return $this;
6✔
60
    }
61

62
    public function addClass(Concept $class): self
63
    {
64
        $this->classes[$class->getId()] = $class;
6✔
65

66
        return $this;
6✔
67
    }
68

69
    public function addNamespace(ConceptNamespace $namespace): self
70
    {
71
        $this->namespaces[] = $namespace;
×
72

73
        return $this;
×
74
    }
75

76
    public function addRelationship(Relationship $relationship): self
77
    {
78
        $this->relationships[] = $relationship;
×
79

80
        return $this;
×
81
    }
82

83
    public function render(): string
84
    {
85
        $result = [];
18✔
86

87
        if ($this->title !== null) {
18✔
88
            $result[] = \sprintf('---%s---', \PHP_EOL . 'title: ' . $this->title . \PHP_EOL);
6✔
89
        }
90

91
        $result[] = 'classDiagram';
18✔
92

93
        if ($this->direction !== null) {
18✔
94
            $result[] = \sprintf('direction %s', $this->direction->value);
6✔
95
        }
96

97
        foreach ($this->namespaces as $namespace) {
18✔
98
            $result[] = $namespace;
×
99
        }
100

101
        foreach ($this->classes as $class) {
18✔
102
            $result[] = $class;
6✔
103
        }
104

105
        foreach ($this->relationships as $relationship) {
18✔
106
            $result[] = $relationship;
×
107
        }
108

109
        $result[] = '';
18✔
110

111
        return \implode(\PHP_EOL, $result);
18✔
112
    }
113

114
    public function getParams(): array
115
    {
116
        return \array_filter([
×
UNCOV
117
            'title'     => $this->title,
×
UNCOV
118
            'direction' => $this->direction?->value,
×
UNCOV
119
        ], static fn ($value) => $value !== null);
×
120
    }
121

122
    /**
123
     * @param  array<string>  $params
124
     * @throws \JsonException
125
     */
126
    public function renderHtml(array $params = []): string
127
    {
UNCOV
128
        return Render::html($this, $params);
×
129
    }
130

131
    public function getLiveEditorUrl(): string
132
    {
UNCOV
133
        return Helper::getLiveEditorUrl($this);
×
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc