Completed
Push — master ( a0d4dc...a17c0a )
by Igor
02:03
created

PropertyGenerator::generate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 9.392
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
namespace Leaditin\Code\Generator;
4
5
use Leaditin\Code\DocBlock;
6
use Leaditin\Code\Member\Property;
7
use Leaditin\Code\Tag;
8
9
/**
10
 * @package Leaditin\Code
11
 * @author Igor Vuckovic <[email protected]>
12
 * @license MIT
13
 */
14
class PropertyGenerator extends Generator
15
{
16
    /**
17
     * @var DocBlockGenerator
18
     */
19
    protected $docBlockGenerator;
20
21
    /**
22
     * @var TypeGenerator
23
     */
24
    protected $typeGenerator;
25
26
    /**
27
     * @var ValueGenerator
28
     */
29
    protected $valueGenerator;
30
31
    /**
32
     * @var VisibilityGenerator
33
     */
34
    protected $visibilityGenerator;
35
36
    /**
37
     * @param DocBlockGenerator $docBlockGenerator
38
     * @param TypeGenerator $typeGenerator
39
     * @param ValueGenerator $valueGenerator
40
     * @param VisibilityGenerator $visibilityGenerator
41
     */
42 4 View Code Duplication
    public function __construct(
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...
43
        DocBlockGenerator $docBlockGenerator,
44
        TypeGenerator $typeGenerator,
45
        ValueGenerator $valueGenerator,
46
        VisibilityGenerator $visibilityGenerator
47
    ) {
48 4
        $this->docBlockGenerator = $docBlockGenerator;
49 4
        $this->typeGenerator = $typeGenerator;
50 4
        $this->valueGenerator = $valueGenerator;
51 4
        $this->visibilityGenerator = $visibilityGenerator;
52
53 4
        $this->setDepth(1);
54 4
        $this->docBlockGenerator->setDepth(1);
55 4
    }
56
57
    /**
58
     * @param Property $property
59
     *
60
     * @return string
61
     */
62 4
    public function generate(Property $property): string
63
    {
64 4
        $output = $this->generateLine(
65 4
            $this->docBlockGenerator->generate(
66 4
                new DocBlock(
67 4
                    null,
68 4
                    null,
69
                    [
70 4
                        new Tag('var', $this->typeGenerator->generate($property->type()))
71
                    ]
72
                )
73
            ),
74
            0
75
        );
76
77 4
        $line = $this->visibilityGenerator->generate($property->visibility());
78
79 4
        if ($property->isStatic()) {
80 1
            $line .= ' static';
81
        }
82
83 4
        $line .= ' $' . $property->name();
84
85 4
        if ($property->defaultValue()->value() !== null) {
86 3
            $line .= ' = ' . $this->valueGenerator->generate($property->defaultValue());
87
        }
88
89 4
        $line .= ';';
90
91 4
        $output .= $this->generateLine($line);
92
93 4
        return rtrim($output, $this->endOfLine);
94
    }
95
}
96