Failed Conditions
Push — slika ( 514bb6...d2bd34 )
by Andreas
06:39 queued 03:20
created

Externallink   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A preConnect() 0 18 3
A connectTo() 0 7 2
A getSort() 0 4 1
A getPatterns() 0 4 1
1
<?php
2
3
namespace dokuwiki\Parsing\ParserMode;
4
5
class Externallink extends AbstractMode
6
{
7
    protected $schemes = array();
8
    protected $patterns = array();
9
10
    /** @inheritdoc */
11
    public function preConnect()
12
    {
13
        if (count($this->patterns)) return;
14
15
        $ltrs = '\w';
16
        $gunk = '/\#~:.?+=&%@!\-\[\]';
17
        $punc = '.:?\-;,';
18
        $host = $ltrs.$punc;
19
        $any  = $ltrs.$gunk.$punc;
20
21
        $this->schemes = getSchemes();
22
        foreach ($this->schemes as $scheme) {
23
            $this->patterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
24
        }
25
26
        $this->patterns[] = '(?<=\s)(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
27
        $this->patterns[] = '(?<=\s)(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
28
    }
29
30
    /** @inheritdoc */
31
    public function connectTo($mode)
32
    {
33
34
        foreach ($this->patterns as $pattern) {
35
            $this->Lexer->addSpecialPattern($pattern, $mode, 'externallink');
36
        }
37
    }
38
39
    /** @inheritdoc */
40
    public function getSort()
41
    {
42
        return 330;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getPatterns()
49
    {
50
        return $this->patterns;
51
    }
52
}
53