• 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

76.09
/src/Texy/Modules/FigureModule.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\Patterns;
14

15

16
/**
17
 * The captioned figures.
18
 */
19
final class FigureModule extends Texy\Module
20
{
21
        /** non-floated box CSS class */
22
        public ?string $class = 'figure';
23

24
        /** left-floated box CSS class */
25
        public ?string $leftClass = null;
26

27
        /** right-floated box CSS class */
28
        public ?string $rightClass = null;
29

30
        /** how calculate div's width */
31
        public int|false $widthDelta = 10;
32

33

34
        public function __construct(Texy\Texy $texy)
1✔
35
        {
36
                $this->texy = $texy;
1✔
37

38
                $texy->addHandler('figure', $this->solve(...));
1✔
39

40
                // [* urls .(title)[class]{style} >]
41
                $texy->registerBlockPattern(
1✔
42
                        $this->pattern(...),
1✔
43
                        '~^
44
                                \[\*\ *+                          # opening bracket with asterisk
45
                                ([^\n' . Patterns::MARK . ']{1,1000}) # URLs (1)
46
                                ' . Patterns::MODIFIER . '?       # modifier (2)
47
                                \ *+
48
                                ( \* | (?<! < ) > | < )           # alignment (3)
49
                                \]
50
                                (?:
51
                                        :(' . Patterns::LINK_URL . ' | : ) # link or colon (4)
52
                                )??
53
                                \ ++ \*\*\* \ ++                  # separator
54
                                (.{0,2000})                       # figure content (5)
55
                                ' . Patterns::MODIFIER_H . '?     # modifier (6)
1✔
56
                        $~mU',
57
                        'figure',
1✔
58
                );
59
        }
1✔
60

61

62
        /**
63
         * Callback for [*image*]:link *** .... .(title)[class]{style}>.
64
         */
65
        public function pattern(Texy\BlockParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
66
        {
67
                [, $mURLs, $mImgMod, $mAlign, $mLink, $mContent, $mMod] = $matches;
1✔
68
                // [1] => URLs
69
                // [2] => .(title)[class]{style}<>
70
                // [3] => * < >
71
                // [4] => url | [ref] | [*image*]
72
                // [5] => ...
73
                // [6] => .(title)[class]{style}<>
74

75
                $texy = $this->texy;
1✔
76
                $image = $texy->imageModule->factoryImage($mURLs, $mImgMod . $mAlign);
1✔
77
                $mod = new Texy\Modifier($mMod);
1✔
78
                $mContent = ltrim($mContent);
1✔
79

80
                if ($mLink) {
1✔
81
                        if ($mLink === ':') {
1✔
UNCOV
82
                                $link = new Texy\Link($image->linkedURL ?? $image->URL);
×
UNCOV
83
                                $link->raw = ':';
×
UNCOV
84
                                $link->type = $link::IMAGE;
×
85
                        } else {
86
                                $link = $texy->linkModule->factoryLink($mLink, null, null);
1✔
87
                        }
88
                } else {
89
                        $link = null;
1✔
90
                }
91

92
                return $texy->invokeAroundHandlers('figure', $parser, [$image, $link, $mContent, $mod]);
1✔
93
        }
94

95

96
        /**
97
         * Finish invocation.
98
         */
99
        private function solve(
1✔
100
                Texy\HandlerInvocation $invocation,
101
                Texy\Image $image,
102
                ?Texy\Link $link,
103
                string $content,
104
                Texy\Modifier $mod,
105
        ): ?Texy\HtmlElement
106
        {
107
                $texy = $this->texy;
1✔
108

109
                $hAlign = $image->modifier->hAlign;
1✔
110
                $image->modifier->hAlign = null;
1✔
111

112
                $elImg = $texy->imageModule->solve(null, $image, $link); // returns Texy\HtmlElement or null!
1✔
113
                if (!$elImg) {
1✔
UNCOV
114
                        return null;
×
115
                }
116

117
                $el = new Texy\HtmlElement('div');
1✔
118
                if (!empty($image->width) && $this->widthDelta !== false) {
1✔
119
                        $el->attrs['style']['max-width'] = ($image->width + $this->widthDelta) . 'px';
×
120
                }
121

122
                $mod->decorate($texy, $el);
1✔
123

124
                $el[0] = $elImg;
1✔
125
                $el[1] = new Texy\HtmlElement('p');
1✔
126
                $el[1]->parseLine($texy, ltrim($content));
1✔
127

128
                $class = $this->class;
1✔
129
                if ($hAlign) {
1✔
UNCOV
130
                        $var = $hAlign . 'Class'; // leftClass, rightClass
×
UNCOV
131
                        if (!empty($this->$var)) {
×
UNCOV
132
                                $class = $this->$var;
×
133

UNCOV
134
                        } elseif (empty($texy->alignClasses[$hAlign])) {
×
UNCOV
135
                                $el->attrs['style']['float'] = $hAlign;
×
136

137
                        } else {
UNCOV
138
                                $class .= '-' . $texy->alignClasses[$hAlign];
×
139
                        }
140
                }
141

142
                $el->attrs['class'][] = $class;
1✔
143

144
                return $el;
1✔
145
        }
146
}
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