MacroInlineVariableOutput::runVariableMacro()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
nc 1
cc 3
eloc 10
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ublaboo\Anabelle\Markdown\Macros;
6
7
final class MacroInlineVariableOutput 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
				$line = $this->docuScope->getInlineVariable($input[1]);
19
20
				if ($depth <= parent::MAX_EXECUTE_DEPTH) {
21
					foreach ($this->getMacrosToRunOnInlineVariables() as $macro) {
22
						$macro->runVariableMacro($line, $depth + 1);
23
					}
24
				}
25
26
				return $line;
27
			},
28
			$content
29
		);
30
	}
31
}
32