DocuScope::addBlockVariable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ublaboo\Anabelle\Markdown;
6
7
use Ublaboo\Anabelle\Generator\Exception\DocuGeneratorException;
8
9
final class DocuScope
10
{
11
12
	/**
13
	 * @var string
14
	 */
15
	private $outputDirectory;
16
17
	/**
18
	 * @var string[]
19
	 */
20
	private $inlineVariables = [];
21
22
	/**
23
	 * @var string[]
24
	 */
25
	private $blockVariables = [];
26
27
28
	public function __construct(string $outputDirectory)
29
	{
30
		$this->outputDirectory = $outputDirectory;
31
	}
32
33
34
	public function getOutputDirectory(): string
35
	{
36
		return $this->outputDirectory;
37
	}
38
39
40
	/**
41
	 * @throws DocuGeneratorException
42
	 */
43
	public function addInlineVariable(string $varName, string $value): void
44
	{
45
		if (isset($this->inlineVariables[$varName])) {
46
			throw new DocuGeneratorException(
47
				"You have already defined inline variable [\$$varName]"
48
			);
49
		}
50
51
		$this->inlineVariables[$varName] = $value;
52
	}
53
54
55
	/**
56
	 * @throws DocuGeneratorException
57
	 */
58
	public function getInlineVariable(string $varName): string
59
	{
60
		if (!isset($this->inlineVariables[$varName])) {
61
			throw new DocuGeneratorException(
62
				"Undefined inline variable [\$$varName]"
63
			);
64
		}
65
66
		return $this->inlineVariables[$varName];
67
	}
68
69
70
	/**
71
	 * @throws DocuGeneratorException
72
	 */
73 View Code Duplication
	public function addBlockVariable(string $varName, string $value): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
	{
75
		if (isset($this->blockVariables[$varName])) {
76
			throw new DocuGeneratorException(
77
				"You have already defined block variable [\$$varName]"
78
			);
79
		}
80
81
		$this->blockVariables[$varName] = $value;
82
	}
83
84
85
	/**
86
	 * @throws DocuGeneratorException
87
	 */
88 View Code Duplication
	public function getBlockVariable(string $varName): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
	{
90
		if (!isset($this->blockVariables[$varName])) {
91
			throw new DocuGeneratorException(
92
				"Undefined block variable [\$$varName]"
93
			);
94
		}
95
96
		return $this->blockVariables[$varName];
97
	}
98
}
99