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

JBZoo / Mermaid-PHP / 6309697043

26 Sep 2023 07:53AM UTC coverage: 89.606% (-1.5%) from 91.071%
6309697043

push

github

web-flow
Add Entity Relationship Diagrams (#14)

112 of 112 new or added lines in 9 files covered. (100.0%)

250 of 279 relevant lines covered (89.61%)

44.22 hits per line

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

85.71
/src/ERDiagram/Entity/Entity.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\ERDiagram\Entity;
18

19
use JBZoo\MermaidPHP\Helper;
20

21
class Entity
22
{
23
    private static bool $safeMode   = false;
24
    protected string    $identifier = '';
25
    protected string    $title      = '';
26

27
    /** @var EntityProperty[] */
28
    protected array      $props = [];
29

30
    /**
31
     * @param EntityProperty[] $props
32
     */
33
    public function __construct(string $identifier, string $title = '', array $props = [])
34
    {
35
        $this->identifier = static::isSafeMode() ? Helper::getId($identifier) : $identifier;
88✔
36
        $this->setTitle($title === '' ? $identifier : $title);
88✔
37
        $this->setProps($props);
88✔
38
    }
39

40
    public function __toString(): string
41
    {
42
        if ($this->title !== '') {
88✔
43
            return Helper::escape($this->title);
88✔
44
        }
45

46
        return "{$this->identifier};";
×
47
    }
48

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

53
        return $this;
88✔
54
    }
55

56
    public function getTitle(): string
57
    {
58
        return $this->title === '' ? $this->getId() : $this->title;
×
59
    }
60

61
    /**
62
     * @return EntityProperty[]
63
     */
64
    public function getProps(): array
65
    {
66
        return $this->props;
88✔
67
    }
68

69
    /**
70
     * @param EntityProperty[] $props
71
     */
72
    public function setProps(array $props): void
73
    {
74
        $this->props = $props;
88✔
75
    }
76

77
    public function renderProps(): ?string
78
    {
79
        $spaces = \str_repeat(' ', 4);
16✔
80

81
        $props = $this->getProps();
16✔
82
        if ($props !== []) {
16✔
83
            $output = $this . ' {' . \PHP_EOL;
16✔
84

85
            foreach ($props as $prop) {
16✔
86
                /** @var \JBZoo\MermaidPHP\ERDiagram\Entity\EntityProperty $prop */
87
                $output .= $spaces . $spaces . $prop . \PHP_EOL;
16✔
88
            }
89

90
            return $output . $spaces . '}';
16✔
91
        }
92

93
        return null;
×
94
    }
95

96
    public function getId(): string
97
    {
98
        return $this->identifier;
88✔
99
    }
100

101
    public static function isSafeMode(): bool
102
    {
103
        return self::$safeMode;
88✔
104
    }
105
}
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