Completed
Push — master ( 56471b...43e0f8 )
by Josh
14:46
created

Superscript   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 31 4
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 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 Superscript extends AbstractPass
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 4
	public function parse()
16
	{
17 4
		$pos = $this->text->indexOf('^');
18 4
		if ($pos === false)
19
		{
20 1
			return;
21
		}
22
23 3
		preg_match_all(
24 3
			'/\\^[^\\x17\\s]++/',
25 3
			$this->text,
26 3
			$matches,
27 3
			PREG_OFFSET_CAPTURE,
28 3
			$pos
29
		);
30 3
		foreach ($matches[0] as list($match, $matchPos))
31
		{
32 2
			$matchLen = strlen($match);
33 2
			$startPos = $matchPos;
34 2
			$endPos   = $matchPos + $matchLen;
35
36 2
			$parts = explode('^', $match);
37 2
			unset($parts[0]);
38
39 2
			foreach ($parts as $part)
40
			{
41 2
				$this->parser->addTagPair('SUP', $startPos, 1, $endPos, 0);
42 2
				$startPos += 1 + strlen($part);
43
			}
44
		}
45
	}
46
}