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

un-zero-un / Isocontent / 19911539666

03 Dec 2025 10:57PM UTC coverage: 93.767% (-0.1%) from 93.906%
19911539666

push

gha

346 of 369 relevant lines covered (93.77%)

129.28 hits per line

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

89.47
/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

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

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

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

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

47
            return;
48
        }
49

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