Failed Conditions
Push — psr2 ( de3699...36dc94 )
by Andreas
06:50 queued 03:31
created

Smiley   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A preConnect() 0 10 4
A connectTo() 0 8 3
A getSort() 0 4 1
1
<?php
2
3
namespace dokuwiki\ParserMode;
4
5
class Smiley extends AbstractMode
6
{
7
    protected $smileys = array();
8
    protected $pattern = '';
9
10
    /**
11
     * Smiley constructor.
12
     * @param string[] $smileys
13
     */
14
    public function __construct($smileys)
15
    {
16
        $this->smileys = $smileys;
17
    }
18
19
    /** @inheritdoc */
20
    public function preConnect()
21
    {
22
        if (!count($this->smileys) || $this->pattern != '') return;
23
24
        $sep = '';
25
        foreach ($this->smileys as $smiley) {
26
            $this->pattern .= $sep.'(?<=\W|^)'.Doku_Lexer_Escape($smiley).'(?=\W|$)';
27
            $sep = '|';
28
        }
29
    }
30
31
    /** @inheritdoc */
32
    public function connectTo($mode)
33
    {
34
        if (!count($this->smileys)) return;
35
36
        if (strlen($this->pattern) > 0) {
37
            $this->Lexer->addSpecialPattern($this->pattern, $mode, 'smiley');
38
        }
39
    }
40
41
    /** @inheritdoc */
42
    public function getSort()
43
    {
44
        return 230;
45
    }
46
}
47