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

JBZoo / Mermaid-PHP / 6395852076

26 Sep 2023 07:15PM UTC coverage: 90.214%. Remained the same
6395852076

push

github

web-flow
Add Timeline Diagram (#15)

48 of 48 new or added lines in 3 files covered. (100.0%)

295 of 327 relevant lines covered (90.21%)

45.3 hits per line

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

93.33
/src/Helper.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;
18

19
use JBZoo\MermaidPHP\ERDiagram\ERDiagram;
20
use JBZoo\MermaidPHP\Timeline\Timeline;
21

22
class Helper
23
{
24
    public static function escape(string $text): string
25
    {
26
        $text = \trim($text);
140✔
27
        $text = \htmlentities($text, \ENT_COMPAT);
140✔
28
        $text = \str_replace(['&', '#lt;', '#gt;'], ['#', '<', '>'], $text);
140✔
29

30
        return "\"{$text}\"";
140✔
31
    }
32

33
    public static function getId(string $userFriendlyId): string
34
    {
35
        return \md5($userFriendlyId);
8✔
36
    }
37

38
    public static function getLiveEditorUrl(Graph|ERDiagram|Timeline $mermaid): string
39
    {
40
        $json = \json_encode([
4✔
41
            'code'    => (string)$mermaid,
4✔
42
            'mermaid' => [
2✔
43
                'theme' => 'forest',
2✔
44
            ],
2✔
45
        ]);
2✔
46

47
        if ($json === false) {
4✔
48
            throw new \RuntimeException('Can\'t encode graph to JSON');
×
49
        }
50

51
        $params = \base64_encode($json);
4✔
52

53
        return "https://mermaid-js.github.io/mermaid-live-editor/#/edit/{$params}";
4✔
54
    }
55
}
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