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

h4kuna / data-type / 13238572444

10 Feb 2025 10:20AM UTC coverage: 96.75% (-0.1%) from 96.847%
13238572444

push

github

h4kuna
feat(Collection): add JsonToHtml

11 of 12 new or added lines in 2 files covered. (91.67%)

655 of 677 relevant lines covered (96.75%)

0.97 hits per line

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

90.91
/src/Collection/JsonToHtml.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\DataType\Collection;
4

5
use Nette\Utils\Html;
6
use Nette\Utils\Json;
7
use Stringable;
8

9
abstract class JsonToHtml implements Stringable
10
{
11

12
        public function __construct(private string $_id)
1✔
13
        {
14
        }
1✔
15

16

17
        public function __toString(): string
18
        {
19
                return (string) $this->render();
1✔
20
        }
21

22

23
        public function render(): ?Html
24
        {
25
                $config = get_object_vars($this);
1✔
26
                unset($config['_id']);
1✔
27

28
                if ($config === []) {
1✔
NEW
29
                        return null;
×
30
                }
31
                $el = Html::el('script', Json::encode($config));
1✔
32
                $el->type = 'text/json';
1✔
33
                $el->id = $this->_id;
1✔
34

35
                return $el;
1✔
36
        }
37

38
}
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