Passed
Push — dependabot/composer/symfony/va... ( 2feb6e...564465 )
by
unknown
18:44 queued 11:27
created

CoreRuntime::yesNo()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 3
nc 3
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\Bundle\CoreBundle\Twig\Runtime;
15
16
use Twig\Extension\RuntimeExtensionInterface;
17
18
class CoreRuntime implements RuntimeExtensionInterface
19
{
20
    /**
21
     * Protect a given mail address by finding the text 'x@y' and replacing
22
     * it with HTML entities. This provides protection against email harvesters.
23
     */
24
    public function protectMailAddress(string $string): string
25
    {
26
        $string = preg_replace_callback(
27
            '/(.)@(.)/s',
28
            static function ($m) {
29
                return '&#' . sprintf('%03d', ord($m[1])) . ';&#064;&#' . sprintf('%03d', ord($m[2])) . ';';
30
            },
31
            $string
32
        );
33
34
        return $string;
35
    }
36
}
37