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

dg / texy / 12879605443

21 Jan 2025 03:31AM UTC coverage: 92.224% (+0.03%) from 92.197%
12879605443

push

github

dg
regexp: uses unmatched as null (BC break)

14 of 14 new or added lines in 6 files covered. (100.0%)

101 existing lines in 14 files now uncovered.

2372 of 2572 relevant lines covered (92.22%)

0.92 hits per line

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

89.66
/src/Texy/Modules/ScriptModule.php
1
<?php
2

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

8
declare(strict_types=1);
9

10
namespace Texy\Modules;
11

12
use Texy;
13
use Texy\Regexp;
14

15

16
/**
17
 * Scripts module.
18
 */
19
final class ScriptModule extends Texy\Module
20
{
21
        /** arguments separator */
22
        public string $separator = ',';
23

24

25
        public function __construct(Texy\Texy $texy)
1✔
26
        {
27
                $this->texy = $texy;
1✔
28

29
                $texy->addHandler('script', $this->solve(...));
1✔
30

31
                $texy->registerLinePattern(
1✔
32
                        $this->pattern(...),
1✔
33
                        '~
34
                                \{\{
35
                                ((?:
36
                                        [^' . Texy\Patterns::MARK . '}]++ |  # content not containing }
1✔
37
                                        [}]                     # or single }
38
                                )+)
39
                                \}\}
40
                        ~U',
41
                        'script',
1✔
42
                );
43
        }
1✔
44

45

46
        /**
47
         * Callback for: {{...}}.
48
         */
49
        public function pattern(Texy\LineParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
50
        {
51
                [, $mContent] = $matches;
1✔
52
                // [1] => ...
53

54
                $cmd = trim($mContent);
1✔
55
                if ($cmd === '') {
1✔
UNCOV
56
                        return null;
×
57
                }
58

59
                $raw = null;
1✔
60
                $args = [];
1✔
61
                // function (arg, arg, ...) or function: arg, arg
62
                if ($matches = Regexp::match($cmd, '~^ ([a-z_][a-z0-9_-]*) \s* (?: \( ([^()]*) \) | : (.*) )$~i')) {
1✔
63
                        $cmd = $matches[1];
1✔
64
                        $raw = trim($matches[3] ?? $matches[2]);
1✔
65
                        if ($raw !== '') {
1✔
66
                                $args = Regexp::split($raw, '~\s*' . Regexp::quote($this->separator) . '\s*~');
1✔
67
                        }
68
                }
69

70
                return $this->texy->invokeAroundHandlers('script', $parser, [$cmd, $args, $raw]);
1✔
71
        }
72

73

74
        /**
75
         * Finish invocation.
76
         */
77
        private function solve(
1✔
78
                Texy\HandlerInvocation $invocation,
79
                string $cmd,
80
                ?array $args = null,
81
                ?string $raw = null,
82
        ): Texy\HtmlElement|string|null
83
        {
84
                if ($cmd === 'texy' && $args) {
1✔
85
                        switch ($args[0]) {
1✔
86
                                case 'nofollow':
1✔
UNCOV
87
                                        $this->texy->linkModule->forceNoFollow = true;
×
UNCOV
88
                                        break;
×
89
                        }
90

91
                        return '';
1✔
92
                }
93

94
                return null;
1✔
95
        }
96
}
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