Completed
Push — master ( 66b26f...6fdc54 )
by Vitaly
02:09
created

CommentsGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatSingleLine() 0 4 1
A formatMultiLine() 0 13 2
A code() 0 8 2
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 03.09.16 at 13:02
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Comments block generator.
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class CommentsGenerator extends AbstractGenerator
14
{
15
    protected function formatSingleLine(string $indentation)
16
    {
17
        return $indentation.'/** '.$this->code[0].' */';
18
    }
19
20
    protected function formatMultiLine(string $indentation)
21
    {
22
        $formattedCode = ['/**'];
23
24
        // Prepend inner indentation to code
25
        foreach ($this->code as $codeLine) {
26
            $formattedCode[] = ' * ' . $codeLine;
27
        }
28
29
        $formattedCode[] = ' */';
30
31
        return implode("\n" . $indentation, $formattedCode);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function code($indentation = 0) : string
38
    {
39
        $indentationString = $this->indentation($indentation);
40
41
        return count($this->code) === 1
42
            ? $this->formatSingleLine($indentationString)
43
            : $this->formatMultiLine($indentationString);
44
    }
45
}
46