Completed
Branch wip/litedown (e234a3)
by Josh
31:46 queued 18:30
created

LinkReferences::parse()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 16
cts 16
cp 1
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 0
crap 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 LinkReferences extends AbstractPass
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 263
	public function parse()
16
	{
17 263
		if ($this->text->indexOf(']:') === false)
18 263
		{
19 237
			return;
20
		}
21
22 26
		$regexp = '/^\\x1A* {0,3}\\[([^\\x17\\]]+)\\]: *([^\\s\\x17]+ *(?:"[^\\x17]*?"|\'[^\\x17]*?\'|\\([^\\x17)]*\\))?)[^\\x17\\n]*\\n?/m';
23 26
		preg_match_all($regexp, $this->text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
24 26
		foreach ($matches as $m)
25
		{
26 26
			$this->parser->addIgnoreTag($m[0][1], strlen($m[0][0]), -2);
27
28
			// Only add the reference if it does not already exist
29 26
			$id = strtolower($m[1][0]);
30 26
			if (!isset($this->text->linkReferences[$id]))
31 26
			{
32 26
				$this->text->hasReferences       = true;
33 26
				$this->text->linkReferences[$id] = $m[2][0];
34 26
			}
35 26
		}
36
	}
37
}