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

dg / texy / 42887648368

10 Nov 2026 01:51PM UTC coverage: 96.622% (-0.1%) from 96.735%
42887648368

push

github

dg
Config::$locales: each locale is a list of four quotes (BC break)

Opening and closing double quotes, then the single ones, instead of the pairs
singleQuotes and doubleQuotes. The compatibility layer converts the old table.

cabae8f0-9dec-45ab-a919-45e6dadc3ad6

8 of 8 new or added lines in 3 files covered. (100.0%)

73 existing lines in 18 files now uncovered.

3719 of 3849 relevant lines covered (96.62%)

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\TexyConfig $config,
24
        ) {
25
        }
1 ✔
26

27

28
        /**
29
         * Consumes {{texy: ...}} into DocumentNode::$meta and hands the rest to registered
30
         * handlers. Runs as the first pass, so a handler may still change configuration the
31
         * later ones depend on. A handled directive is removed unless the handler returns
32
         * a replacement.
33
         */
34
        public function processDirectives(Texy\Nodes\DocumentNode $doc): void
35
        {
36
                (new Texy\NodeTraverser)->traverse($doc, function (Texy\Node $node) use ($doc): Texy\Node|Texy\TraverseAction|null {
1 ✔
37
                        if (!$node instanceof DirectiveNode) {
1 ✔
38
                                return null;
1 ✔
39
                        }
40

41
                        if ($node->name === 'texy' && $node->args) {
1 ✔
42
                                foreach ($node->args as $arg) {
1 ✔
43
                                        $doc->meta[$arg] = true;
1 ✔
44
                                }
45
                                return Texy\TraverseAction::Remove;
1 ✔
46
                        }
47

48
                        $handler = $this->config->directives[Texy\Helpers::toLower($node->name)] ?? $this->config->directiveFallback;
1 ✔
49
                        if ($handler === null) {
1 ✔
50
                                return null;
1 ✔
51
                        }
52

53
                        $result = $handler($node);
1 ✔
54
                        return $result instanceof Texy\Node ? $result : Texy\TraverseAction::Remove;
1 ✔
55
                });
1 ✔
56
        }
1 ✔
57

58

59
        public function register(Texy\Parsing\Registry $registry): void
60
        {
61
                $registry->addInline(
1 ✔
62
                        Syntax::Directive,
1 ✔
63
                        '~
1 ✔
64
                                \{\{
65
                                ((?:
66
                                        [^}]++ |   # content not containing }
67
                                        }          # or single }
68
                                )+)
69
                                }}
70
                        ~Ux',
71
                        $this->parse(...),
1 ✔
72
                );
73
        }
1 ✔
74

75

76
        /**
77
         * Parses {{macro}}.
78
         * @param  array{string, string}  $matches
79
         * @param  array{int, int}  $offsets
80
         */
81
        public function parse(ParseContext $context, array $matches, array $offsets): ?DirectiveNode
82
        {
83
                return trim($matches[1]) === ''
1 ✔
UNCOV
84
                        ? null
×
85
                        : new DirectiveNode($matches[1], new Range($offsets[0], strlen($matches[0])));
1 ✔
86
        }
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