MacroBlockVariableOutput   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B runVariableMacro() 0 36 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ublaboo\Anabelle\Markdown\Macros;
6
7
final class MacroBlockVariableOutput extends AbstractMacroVariable implements IMacro
8
{
9
10
	protected function runVariableMacro(string & $content, int $depth): void // Intentionally &
11
	{
12
		/**
13
		 * Remove lines with inline variables definition and put then into DocuScope
14
		 */
15
		$content = preg_replace_callback(
16
			'/(^.*)?\{\$\$([a-zA-Z_0-9]+)\}/m',
17
			function(array $input) use ($depth): string {
18
				$whitespacePrefix = '';
19
20
				/**
21
				 * Prefix the whole block with current identation
22
				 */
23
				foreach (str_split($input[1]) as $character) {
24
					if ($character === "\t") {
25
						$whitespacePrefix .= $character;
26
27
						continue;
28
					}
29
30
					break;
31
				}
32
33
				$block = $this->docuScope->getBlockVariable($input[2]);
34
35
				if ($depth <= parent::MAX_EXECUTE_DEPTH) {
36
					foreach ($this->getMacrosToRunOnBlockVariables() as $macro) {
37
						$macro->runVariableMacro($block, $depth + 1);
38
					}
39
				}
40
41
				return $input[1] . preg_replace('/\n/m', "\n{$whitespacePrefix}", $block);
42
			},
43
			$content
44
		);
45
	}
46
}
47