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

JBZoo / Mermaid-PHP / 6310109909

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

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%)

48.2 hits per line

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

84.0
/src/ERDiagram/Relation/Relation.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\Relation;
18

19
use JBZoo\MermaidPHP\ERDiagram\Entity\Entity;
20
use JBZoo\MermaidPHP\Helper;
21

22
abstract class Relation
23
{
24
    public const ZERO_OR_ONE  = '?';
25
    public const ZERO_OR_MORE = '*';
26
    public const ONE_OR_MORE  = '+';
27

28
    protected static bool $safeMode = false;
29
    protected Entity    $firstEntity;
30
    protected Entity    $secondEntity;
31
    protected string    $identifier   = '';
32
    protected ?string    $action      = '';
33
    protected ?string    $cardinality = null;
34
    protected bool      $identifying  = true;
35

36
    abstract public function getLink(): string;
37

38
    /**
39
     * @codingStandardsIgnoreStart
40
     */
41
    public function __construct(Entity $firstEntity, Entity $secondEntity, ?string $action = null, ?string $cardinality = null, bool $identifying = true)
42
    {
43
        /** @codingStandardsIgnoreEnd  */
44
        $identifier         = $firstEntity . $secondEntity;
84✔
45
        $this->identifier   = static::isSafeMode() ? Helper::getId($identifier) : $identifier;
84✔
46
        $this->firstEntity  = $firstEntity;
84✔
47
        $this->secondEntity = $secondEntity;
84✔
48
        $this->action       = $action;
84✔
49
        $this->cardinality  = $cardinality;
84✔
50
        $this->identifying  = $identifying;
84✔
51
    }
52

53
    public function __toString(): string
54
    {
55
        $action = $this->getAction();
84✔
56
        if ($action === null || $action === '') {
84✔
57
            $action = '""';
4✔
58
        }
59
        $action = ' : ' . $action;
84✔
60

61
        $firstEntity = (string)$this->firstEntity;
84✔
62

63
        $secondEntity = (string)$this->secondEntity;
84✔
64

65
        return \sprintf('%s %s %s%s', $firstEntity, static::getLink(), $secondEntity, $action);
84✔
66
    }
67

68
    public function getId(): string
69
    {
70
        return $this->identifier;
84✔
71
    }
72

73
    public function getAction(): ?string
74
    {
75
        return $this->action;
84✔
76
    }
77

78
    public function setAction(?string $action): void
79
    {
80
        $this->action = $action;
×
81
    }
82

83
    public function getCardinality(): ?string
84
    {
85
        return $this->cardinality;
×
86
    }
87

88
    public function setCardinality(?string $cardinality): void
89
    {
90
        $this->cardinality = $cardinality;
×
91
    }
92

93
    public function isIdentifying(): bool
94
    {
95
        return $this->identifying;
84✔
96
    }
97

98
    public function setIdentifying(bool $identifying): void
99
    {
100
        $this->identifying = $identifying;
×
101
    }
102

103
    public function getIdentification(): string
104
    {
105
        if (!$this->isIdentifying()) {
84✔
106
            return '..';
32✔
107
        }
108

109
        return '--';
52✔
110
    }
111

112
    public static function isSafeMode(): bool
113
    {
114
        return self::$safeMode;
84✔
115
    }
116
}
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