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

JBZoo / Mermaid-PHP / 9513133895

04 Feb 2024 06:07PM UTC coverage: 88.72%. Remained the same
9513133895

push

github

web-flow
Add a few methods to Concept class (#20)

Co-authored-by: Antonio Turdo <antonio.turdo@immobiliare.it>

0 of 3 new or added lines in 1 file covered. (0.0%)

409 of 461 relevant lines covered (88.72%)

59.84 hits per line

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

86.36
/src/ClassDiagram/Concept/Concept.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\Concept;
18

19
use JBZoo\MermaidPHP\Helper;
20

21
class Concept
22
{
23
    private static bool $safeMode = false;
24
    protected string    $identifier;
25

26
    /** @var Attribute[] */
27
    protected array     $attributes;
28

29
    /** @var Method[] */
30
    protected array     $methods;
31

32
    protected ?string   $annotation;
33

34
    /**
35
     * @param Attribute[] $attributes
36
     * @param Method[]    $methods
37
     */
38
    public function __construct(
39
        string $identifier,
40
        array $attributes = [],
41
        array $methods = [],
42
        ?string $annotation = null,
43
    ) {
44
        $this->identifier = static::isSafeMode() ? Helper::getId($identifier) : $identifier;
48✔
45
        $this->attributes = $attributes;
48✔
46
        $this->methods    = $methods;
48✔
47
        $this->annotation = $annotation;
48✔
48
    }
49

50
    public function __toString(): string
51
    {
52
        $result = $this->getLinesToRender();
18✔
53

54
        return \implode(\PHP_EOL, $result);
18✔
55
    }
56

57
    public function getLinesToRender(): array
58
    {
59
        $spaces = \str_repeat(' ', 4);
24✔
60

61
        $result = [];
24✔
62

63
        $result[] = \sprintf('class %s {', $this->identifier);
24✔
64

65
        if ($this->annotation !== null) {
24✔
66
            $result[] = $spaces . \sprintf('<<%s>>', $this->annotation);
6✔
67
        }
68

69
        foreach ($this->attributes as $attribute) {
24✔
70
            $result[] = $spaces . $attribute;
18✔
71
        }
72

73
        foreach ($this->methods as $method) {
24✔
74
            $result[] = $spaces . $method;
6✔
75
        }
76

77
        $result[] = '}';
24✔
78

79
        return $result;
24✔
80
    }
81

82
    public function getId(): string
83
    {
84
        return $this->identifier;
30✔
85
    }
86

87
    public function addAttribute(Attribute $attribute): void
88
    {
NEW
89
        $this->attributes[] = $attribute;
×
90
    }
91

92
    public function addMethod(Method $method): void
93
    {
NEW
94
        $this->methods[] = $method;
×
95
    }
96

97
    public function setAnnotation(string $annotation): void
98
    {
NEW
99
        $this->annotation = $annotation;
×
100
    }
101

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

© 2025 Coveralls, Inc