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

un-zero-un / Isocontent / 19910422417

03 Dec 2025 10:09PM UTC coverage: 93.906% (-0.6%) from 94.49%
19910422417

push

gha

339 of 361 relevant lines covered (93.91%)

128.66 hits per line

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

94.12
/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]
112✔
14
    public function parse(Builder $builder, mixed $input): void
15
    {
16
        if (!\is_array($input)) {
112✔
17
            throw new UnsupportedFormatException();
×
18
        }
19

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

23
            return;
24
        }
25

72✔
26
        /** @var array $node */
27
        foreach ($input as $node) {
28
            $this->parseNode($builder, $node);
72✔
29
        }
30
    }
31

112✔
32
    #[\Override]
33
    public function supportsFormat(string $format): bool
112✔
34
    {
112✔
35
        return 'array' === $format;
36
    }
112✔
37

38
    private function parseNode(Builder $builder, array $node): void
39
    {
112✔
40
        if (Node::TYPE_TEXT === $node['type']) {
112✔
41
            assert(is_string($node['value']));
42
            $builder->addTextNode($node['value']);
112✔
43

44
            return;
112✔
45
        }
112✔
46

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

58
        $childBuilder = $builder->addBlockNode($blockType, $node['arguments'] ?? []);
59

60
        if (null !== $childNodes) {
61
            foreach ($childNodes as $childNode) {
62
                $this->parseNode($childBuilder, $childNode);
63
            }
64
        }
65
    }
66
}
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