CustomParsedown::inlineSection()   B
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 14
nc 5
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ublaboo\Anabelle\Parsedown;
6
7
use Nette\Utils\Strings;
8
9
final class CustomParsedown extends \Parsedown
10
{
11
12
	function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
13
	{
14
		$this->InlineTypes['@'][]= 'Section';
15
16
		$this->inlineMarkerList .= '@';
17
	}
18
19
20
	/**
21
	 * Either "section" or "home" element
22
	 */
23
	protected function inlineSection($excerpt): ?array
24
	{
25
		if (preg_match('/^(@@?) ?(.+[^:]):(.+\.(php|html))/', $excerpt['text'], $matches)) {
26
			$class = strlen($matches[1]) == 1 ? 'section-site' : 'section-method';
27
			$element = strlen($matches[1]) == 1 ? 'a' : 'button';
28
29
			return [
30
				'extent' => strlen($matches[0]), 
31
				'element' => [
32
					'name' => $element,
33
					'text' => $matches[2],
34
					'attributes' => [
35
						'data-section-src' => $matches[3],
36
						'class' => $class,
37
						'data-target' => Strings::webalize($matches[2])
38
					]
39
				]
40
			];
41
		}
42
43
		return null;
44
	}
45
}
46