bbcodes_legacy::set_data()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 3
nop 0
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 4
rs 10
c 0
b 0
f 0
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
use phpbb\config\config;
0 ignored issues
show
Bug introduced by
The type phpbb\config\config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
class bbcodes_legacy extends base
16
{
17
	/** @var config */
18
	protected $config;
19
20
	/** @var string Regex data of BBCodes to remove */
21
	protected $data;
22
23
	/**
24
	 * Constructor
25
	 *
26
	 * @param config $config Config object
27
	 */
28 38
	public function __construct(config $config)
29
	{
30 38
		$this->config = $config;
31 38
	}
32
33
	/**
34
	 * @inheritdoc
35
	 */
36 28
	public function run()
37
	{
38 28
		return $this->set_data()->process();
39
	}
40
41
	/**
42
	 * @inheritdoc
43
	 */
44 28
	public function set_data()
45
	{
46 28
		if (!isset($this->data) || is_array($this->data))
47 28
		{
48 28
			$strip_bbcodes = !empty($this->config['topic_preview_strip_bbcodes']) ? 'flash|' . trim($this->config['topic_preview_strip_bbcodes']) : 'flash';
49 28
			$this->data = '#\[(' . $strip_bbcodes . ')[^\[\]]*\]((?:(?!\[\1[^\[\]]*\]).)*)\[\/\1[^\[\]]*\]#Usi';
50 28
		}
51
52 28
		return $this;
53
	}
54
55
	/**
56
	 * Remove specified BBCodes and their contents
57
	 * Uses recursion to handle nested BBCodes
58
	 *
59
	 * @return string Stripped message text
60
	 */
61 28
	protected function process()
62
	{
63 28
		if (preg_match($this->data, $this->text))
64 28
		{
65 13
			$this->text = preg_replace($this->data, '', $this->text);
66 13
			return $this->process();
67
		}
68
69 28
		return $this->text;
70
	}
71
}
72