Failed Conditions
Push — psr2 ( e9eace...d4d8fb )
by Andreas
07:52
created

Entity::getSort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Parsing\ParserMode;
4
5
use dokuwiki\Parsing\Lexer\Lexer;
6
7
class Entity extends AbstractMode
8
{
9
10
    protected $entities = array();
11
    protected $pattern = '';
12
13
    /**
14
     * Entity constructor.
15
     * @param string[] $entities
16
     */
17
    public function __construct($entities)
18
    {
19
        $this->entities = $entities;
20
    }
21
22
23
    /** @inheritdoc */
24
    public function preConnect()
25
    {
26
        if (!count($this->entities) || $this->pattern != '') return;
27
28
        $sep = '';
29
        foreach ($this->entities as $entity) {
30
            $this->pattern .= $sep. Lexer::escape($entity);
31
            $sep = '|';
32
        }
33
    }
34
35
    /** @inheritdoc */
36
    public function connectTo($mode)
37
    {
38
        if (!count($this->entities)) return;
39
40
        if (strlen($this->pattern) > 0) {
41
            $this->Lexer->addSpecialPattern($this->pattern, $mode, 'entity');
42
        }
43
    }
44
45
    /** @inheritdoc */
46
    public function getSort()
47
    {
48
        return 260;
49
    }
50
}
51