GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( f5e6b3...c7b627 )
by Christian
02:34
created

UrlAutoConverterTwigExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertLinks() 0 21 3
A getFilters() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Twig\Extension;
13
14
use Twig\Extension\AbstractExtension;
15
use Twig\TwigFilter;
16
17
final class UrlAutoConverterTwigExtension extends AbstractExtension
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getFilters()
23
    {
24
        return [
25
            new TwigFilter('converturls', [$this, 'convertLinks'], [
26
                'is_safe' => ['html'],
27
            ]),
28
        ];
29
    }
30
31
    /**
32
     * @param string $text
33
     * @param array  $options
34
     *
35
     * @return string
36
     */
37
    public function convertLinks(string $text, array $options = []): string
38
    {
39
        // https://bitbucket.org/kwi/urllinker/
40
        $text = preg_replace('#(script|about|applet|activex|chrome):#is', '\\1:', $text) ?: '';
41
        $ret  = ' '.$text;
42
43
        $attr = '';
44
        foreach ($options as $key => $value) {
45
            $attr .= ' '.$key.'="'.$value.'"';
46
        }
47
48
        // Replace Links with http://
49
        $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", '\\1<a href="\\2"'.$attr.'>\\2</a>', $ret);
50
51
        // Replace Links without http://
52
        $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", '\\1<a href="http://\\2"'.$attr.'>\\2</a>', $ret);
53
54
        // Replace Email Addresses
55
        $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '\\1<a href="mailto:\\2@\\3"'.$attr.'>\\2@\\3</a>', $ret);
56
57
        return substr($ret, 1);
58
    }
59
}
60