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

dg / texy / 43760211708

15 Nov 2026 08:43PM UTC coverage: 97.217% (+0.3%) from 96.951%
43760211708

push

github

dg
cs

3 of 5 new or added lines in 1 file covered. (60.0%)

45 existing lines in 12 files now uncovered.

3878 of 3989 relevant lines covered (97.22%)

0.97 hits per line

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

96.0
/src/Modules/DirectiveModule.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Texy! (https://texy.deegee.dev)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Texy\Modules;
9

10
use Texy;
11
use Texy\Nodes\DirectiveNode;
12
use Texy\Parsing\ParseContext;
13
use Texy\{Range, Syntax};
14
use function strlen;
15

16

17
/**
18
 * Processes {{macro}} script commands.
19
 */
20
final class DirectiveModule extends Texy\Module
21
{
22
        public function __construct(
1 ✔
23
                private Texy\Config $config,
24
        ) {
25
        }
1 ✔
26

27

28
        public function register(Texy\Parsing\Engine $engine): void
29
        {
30
                $engine->addInline(
1 ✔
31
                        Syntax::Directive,
1 ✔
32
                        '~
1 ✔
33
                                \{\{
34
                                ((?:
35
                                        [^}]++ |   # content not containing }
36
                                        }          # or single }
37
                                )+)
38
                                }}
39
                        ~Ux',
40
                        $this->parse(...),
1 ✔
41
                );
42
        }
1 ✔
43

44

45
        /**
46
         * Parses {{macro}}.
47
         * @param  array{string, string}  $matches
48
         * @param  array{int, int}  $offsets
49
         */
50
        public function parse(ParseContext $context, array $matches, array $offsets): ?DirectiveNode
51
        {
52
                return trim($matches[1]) === ''
1 ✔
UNCOV
53
                        ? null
×
54
                        : new DirectiveNode($matches[1], new Range($offsets[0], strlen($matches[0])));
1 ✔
55
        }
56

57

58
        /**
59
         * Consumes {{texy: ...}} into DocumentNode::$meta and hands the rest to the directive
60
         * handler. Runs as the first pass, so the handler may still change configuration the
61
         * later ones depend on. A handled directive is removed unless the handler returns
62
         * a replacement.
63
         */
64
        public function processDirectives(Texy\Nodes\DocumentNode $doc): void
65
        {
66
                (new Texy\NodeTraverser)->traverse($doc, function (Texy\Node $node) use ($doc): Texy\Node|Texy\TraverseAction|null {
1 ✔
67
                        if (!$node instanceof DirectiveNode) {
1 ✔
68
                                return null;
1 ✔
69
                        }
70

71
                        if ($node->name === 'texy' && $node->args) {
1 ✔
72
                                foreach ($node->args as $arg) {
1 ✔
73
                                        $doc->meta[$arg] = true;
1 ✔
74
                                }
75
                                return Texy\TraverseAction::Remove;
1 ✔
76
                        }
77

78
                        $handler = $this->config->directiveHandler;
1 ✔
79
                        if ($handler === null) {
1 ✔
80
                                return null;
1 ✔
81
                        }
82

83
                        $result = $handler($node);
1 ✔
84
                        return $result instanceof Texy\Node ? $result : Texy\TraverseAction::Remove;
1 ✔
85
                });
1 ✔
86
        }
1 ✔
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc