Completed
Push — master ( 2a5486...81459b )
by Vitaly
02:39
created

FunctionGenerator::code()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 03.09.16 at 11:30
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Function generation class.
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class FunctionGenerator extends AbstractGenerator
14
{
15
    /** @var string Function name */
16
    protected $name;
17
18
    /**
19
     * FunctionGenerator constructor.
20
     *
21
     * @param GenericGenerator $parent Parent Generator
22
     * @param string           $name Function name
23
     */
24
    public function __construct(string $name, GenericGenerator $parent = null)
25
    {
26
        $this->name = $name;
27
28
        parent::__construct($parent);
29
    }
30
31
    /**
32
     * Build function definition.
33
     *
34
     * @return string Function definition
35
     */
36
    protected function buildDefinition()
37
    {
38
        return 'function '.$this->name.'()';
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 View Code Duplication
    public function code($indentation = 0) : 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...
45
    {
46
        $innerIndentation = $this->indentation(1);
47
48
        $formattedCode = [
49
            $this->buildDefinition(),
50
            '{'
51
        ];
52
        // Prepend inner indentation to code
53
        foreach ($this->code as $codeLine) {
54
            $formattedCode[] = $innerIndentation.$codeLine;
55
        }
56
        $formattedCode[] = '}';
57
58
        return implode("\n".$this->indentation($indentation), $formattedCode);
59
    }
60
}
61