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

un-zero-un / Isocontent / 23819482218

31 Mar 2026 09:09PM UTC coverage: 99.789% (-0.2%) from 100.0%
23819482218

push

gha

474 of 475 relevant lines covered (99.79%)

162.54 hits per line

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

95.65
/src/Parser/ArrayParser.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Isocontent\Parser;
6

7
use Isocontent\AST\Builder;
8
use Isocontent\AST\Node;
9
use Isocontent\Exception\UnsupportedFormatException;
10

11
final class ArrayParser implements Parser
12
{
13
    #[\Override]
184✔
14
    public function parse(Builder $builder, mixed $input): void
15
    {
16
        if (!\is_array($input)) {
184✔
17
            throw new UnsupportedFormatException();
8✔
18
        }
19

20
        if (isset($input['type'])) {
176✔
21
            $this->parseNode($builder, $input);
8✔
22

23
            return;
8✔
24
        }
25

26
        foreach ($input as $node) {
168✔
27
            if (!\is_array($node)) {
168✔
28
                throw new UnsupportedFormatException();
×
29
            }
30

31
            $this->parseNode($builder, $node);
168✔
32
        }
33
    }
34

35
    #[\Override]
80✔
36
    public function supportsFormat(string $format): bool
37
    {
38
        return 'array' === $format;
80✔
39
    }
40

41
    private function parseNode(Builder $builder, array $node): void
176✔
42
    {
43
        if (Node::TYPE_TEXT === $node['type']) {
176✔
44
            assert(is_string($node['value']));
160✔
45
            $builder->addTextNode($node['value']);
160✔
46

47
            return;
160✔
48
        }
49

50
        /**
51
         * @var array{
52
         *     type: 'block',
53
         *     block_type:  string,
54
         *     arguments?: array<string, scalar>,
55
         *     children?: array<array>,
56
         * } $node
57
         * */
58
        $childNodes = $node['children'] ?? null;
168✔
59
        $blockType = $node['block_type'];
168✔
60

61
        $childBuilder = $builder->addBlockNode($blockType, $node['arguments'] ?? []);
168✔
62

63
        if (null !== $childNodes) {
168✔
64
            foreach ($childNodes as $childNode) {
144✔
65
                $this->parseNode($childBuilder, $childNode);
144✔
66
            }
67
        }
68
    }
69
}
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