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

Smiley::preConnect()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 3
dl 0
loc 10
c 0
b 0
f 0
cc 4
eloc 6
nop 0
rs 9.2
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