markup   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 42
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 3 1
A set_data() 0 16 2
A run() 0 3 1
1
<?php
2
/**
3
 *
4
 * Topic Preview
5
 *
6
 * @copyright (c) 2016 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\topicpreview\core\trim\tools;
12
13
class markup extends base
14
{
15
	/** @var array Data array of regex patterns */
16
	protected $data;
17
18
	/**
19
	 * @inheritdoc
20
	 */
21 28
	public function run()
22
	{
23 28
		return $this->set_data()->process();
24
	}
25
26
	/**
27
	 * @inheritdoc
28
	 */
29 28
	public function set_data()
30
	{
31 28
		if (!isset($this->data))
32 28
		{
33
			// RegEx patterns originally based on Topic Text Hover Mod by RMcGirr83
34 28
			$this->data = array(
35 28
				'#<!-- [lmw] --><a class="postlink[^>]*>(.*<\/a[^>]*>)?<!-- [lmw] -->#Usi', // Magic URLs
36 28
				'#<[^>]*>(.*<[^>]*>)?#Usi', // HTML code
37 28
				'#\[/?[^\[\]]+\]#mi', // All BBCode tags
38 28
				'#(http|https|ftp|mailto)(:|\&\#58;)\/\/[^\s]+#i', // Remaining URLs
39 28
				'#"#', // Possible un-encoded quotes from older board conversions
40
				'#[ \t]{2,}#' // Multiple spaces #[\s]+#
41 28
			);
42 28
		}
43
44 28
		return $this;
45
	}
46
47
	/**
48
	 * Remove markup from the text
49
	 *
50
	 * @return string Stripped message text
51
	 */
52 28
	protected function process()
53
	{
54 28
		return trim(preg_replace($this->data, ' ', $this->text));
55
	}
56
}
57