Generator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 43
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDepth() 0 6 1
A generateLine() 0 6 1
1
<?php
2
3
namespace Leaditin\Code\Generator;
4
5
/**
6
 * @package Leaditin\Code
7
 * @author Igor Vuckovic <[email protected]>
8
 * @license MIT
9
 */
10
abstract class Generator
11
{
12
    /**
13
     * @var string
14
     */
15
    public const INDENTATION = '    ';
16
17
    /**
18
     * @var string
19
     */
20
    public const END_OF_LINE = PHP_EOL;
21
22
    /**
23
     * @var int
24
     */
25
    protected $depth = 0;
26
27
    /**
28
     * @param int $depth
29
     *
30
     * @return static
31
     */
32 18
    public function setDepth(int $depth): self
33
    {
34 18
        $this->depth = $depth;
35
36 18
        return $this;
37
    }
38
39
    /**
40
     * @param string $text
41
     * @param null|int $numberOfIndentationBefore
42
     * @param int $numberOfEmptyLinesAfter
43
     *
44
     * @return string
45
     */
46 17
    protected function generateLine(string $text, int $numberOfIndentationBefore = null, int $numberOfEmptyLinesAfter = 0): string
47
    {
48 17
        return str_repeat(static::INDENTATION, $numberOfIndentationBefore ?? $this->depth)
49 17
            . $text
50 17
            . str_repeat(static::END_OF_LINE, ++$numberOfEmptyLinesAfter);
51
    }
52
}
53