Completed
Push — master ( a3e52e...3da711 )
by Josh
01:34
created

AbstractInlineMarkup   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
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 32
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseInlineMarkup() 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
abstract class AbstractInlineMarkup extends AbstractPass
11
{
12
	/**
13
	* Parse given inline markup in text
14
	*
15
	* The markup must start and end with exactly 2 characters
16
	*
17
	* @param  string $str     First markup string
18
	* @param  string $regexp  Regexp used to match the markup's span
19
	* @param  string $tagName Name of the tag produced by this markup
20
	* @return void
21
	*/
22 16
	protected function parseInlineMarkup(string $str, string $regexp, string $tagName): void
23
	{
24 16
		$pos = $this->text->indexOf($str);
25 16
		if ($pos === false)
26
		{
27 16
			return;
28
		}
29
30 14
		preg_match_all($regexp, $this->text, $matches, PREG_OFFSET_CAPTURE, $pos);
31 14
		foreach ($matches[0] as [$match, $matchPos])
32
		{
33 11
			$matchLen = strlen($match);
0 ignored issues
show
Bug introduced by
The variable $match does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
34 11
			$endPos   = $matchPos + $matchLen - 2;
0 ignored issues
show
Bug introduced by
The variable $matchPos does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
35
36 11
			$this->parser->addTagPair($tagName, $matchPos, 2, $endPos, 2);
37 11
			$this->text->overwrite($matchPos, 2);
38 11
			$this->text->overwrite($endPos, 2);
39
		}
40
	}
41
}