DocuScope   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getOutputDirectory() 0 4 1
A addInlineVariable() 0 10 2
A getInlineVariable() 0 10 2
A addBlockVariable() 10 10 2
A getBlockVariable() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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