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

dg / texy / 22262589061

21 Feb 2026 07:04PM UTC coverage: 92.991% (+1.8%) from 91.178%
22262589061

push

github

dg
LinkModule: deprecated label and modifiers in link definitions

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

126 existing lines in 22 files now uncovered.

2083 of 2240 relevant lines covered (92.99%)

0.93 hits per line

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

96.43
/src/Texy/Modules/EmoticonModule.php
1
<?php declare(strict_types=1);
2

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

8
namespace Texy\Modules;
9

10
use Texy;
11
use function implode, krsort, str_contains, trigger_error;
12

13

14
/**
15
 * Replaces emoticons with images or Unicode characters.
16
 */
17
final class EmoticonModule extends Texy\Module
18
{
19
        /** @var array<string, string> */
20
        public array $icons = [
21
                ':-)' => '🙂',
22
                ':-(' => '☹',
23
                ';-)' => '😉',
24
                ':-D' => '😁',
25
                '8-O' => '😮',
26
                '8-)' => '😄',
27
                ':-?' => '😕',
28
                ':-x' => '😶',
29
                ':-P' => '😛',
30
                ':-|' => '😐',
31
        ];
32

33
        /** CSS class for emoticons */
34
        public ?string $class = null;
35

36

37
        public function __construct(
1✔
38
                private Texy\Texy $texy,
39
        ) {
40
                $texy->allowed['emoticon'] = false;
1✔
41
                $texy->addHandler('emoticon', $this->solve(...));
1✔
42
        }
1✔
43

44

45
        public function beforeParse(string &$text): void
1✔
46
        {
47
                if (str_contains(implode('', $this->icons), '.')) {
1✔
48
                        trigger_error('EmoticonModule: using image files is deprecated, use Unicode characters instead.', E_USER_DEPRECATED);
1✔
49
                }
50

51
                krsort($this->icons);
1✔
52
                $pattern = [];
1✔
53
                foreach ($this->icons as $key => $foo) {
1✔
54
                        $pattern[] = Texy\Regexp::quote($key) . '+'; // last char can be repeated
1✔
55
                }
56

57
                $this->texy->registerLinePattern(
1✔
58
                        $this->parse(...),
1✔
59
                        '~
60
                                (?<= ^ | [\x00-\x20] )
61
                                (' . implode('|', $pattern) . ')
1✔
62
                        ~',
63
                        'emoticon',
1✔
64
                        '~' . implode('|', $pattern) . '~',
1✔
65
                );
66
        }
1✔
67

68

69
        /**
70
         * Parses :-).
71
         * @param  array<?string>  $matches
72
         */
73
        public function parse(Texy\InlineParser $parser, array $matches): Texy\HtmlElement|string|null
1✔
74
        {
75
                $match = $matches[0];
1✔
76

77
                // find the closest match
78
                foreach ($this->icons as $emoticon => $foo) {
1✔
79
                        if (str_starts_with($match, $emoticon)) {
1✔
80
                                return $this->texy->invokeAroundHandlers('emoticon', $parser, [$emoticon, $match]);
1✔
81
                        }
82
                }
83

UNCOV
84
                return null;
×
85
        }
86

87

88
        /**
89
         * Finish invocation.
90
         */
91
        private function solve(Texy\HandlerInvocation $invocation, string $emoticon): Texy\HtmlElement|string
1✔
92
        {
93
                $emoji = $this->icons[$emoticon];
1✔
94
                return $this->class
1✔
95
                        ? (new Texy\HtmlElement('span', ['class' => $this->class]))->setText($emoji)
1✔
96
                        : $emoji;
1✔
97
        }
98
}
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