Completed
Branch 2.1/LitedownSpoiler (7c54ca)
by Josh
01:28
created

InlineSpoiler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 19 3
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2019 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\Litedown\Parser\Passes;
9
10
class InlineSpoiler extends AbstractPass
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 6
	public function parse()
16
	{
17 6
		$pos = $this->text->indexOf('>!');
18 6
		if ($pos === false)
19
		{
20 1
			return;
21
		}
22
23 5
		preg_match_all('/>![^\\x17]+?!</', $this->text, $matches, PREG_OFFSET_CAPTURE, $pos);
24 5
		foreach ($matches[0] as list($match, $matchPos))
25
		{
26 4
			$matchLen = strlen($match);
27 4
			$endPos   = $matchPos + $matchLen - 2;
28
29 4
			$this->parser->addTagPair('ISPOILER', $matchPos, 2, $endPos, 2);
30 4
			$this->text->overwrite($matchPos, 2);
31 4
			$this->text->overwrite($endPos, 2);
32
		}
33
	}
34
}