• 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
        foreach ($input as $node) {
27
            if (!\is_array($node)) {
28
                throw new UnsupportedFormatException();
72✔
29
            }
30

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

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

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

112✔
47
            return;
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;
59
        $blockType = $node['block_type'];
60

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

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