Preprocessor::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Plugin\BbcodeParser\src\Lib;
14
15
class Preprocessor
16
{
17
    protected $_settings;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param array $settings settings
23
     */
24
    public function __construct($settings)
25
    {
26
        $this->_settings = $settings;
27
    }
28
29
    /**
30
     * Process
31
     *
32
     * @param string $string string
33
     * @return string
34
     */
35
    public function process($string)
36
    {
37
        return $this->_hashInternalEntryLinks($string);
38
    }
39
40
    /**
41
     * Convert full internal links (http://domain/…/view/123) to hashes (#123)
42
     *
43
     * @param string $string string
44
     * @return string
45
     */
46
    protected function _hashInternalEntryLinks($string)
47
    {
48
        $string = preg_replace(
49
            "%
50
				(?<!=) # don't hash if part of [url=…
51
				{$this->_settings->get('server')}{$this->_settings->get('webroot')}{$this->_settings->get('hashBaseUrl')}
52
				(\d+)  # the id
53
				%imx",
54
            "#\\1",
55
            $string
56
        );
57
58
        return $string;
59
    }
60
}
61