AddResolverProperty::buildProperty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework. Cycle ProxyFactory
5
 *
6
 * @license MIT
7
 * @author  Valentin V (Vvval)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\ORM\Promise\Visitor;
13
14
use Cycle\ORM\Promise\PHPDoc;
15
use PhpParser\Builder\Property;
16
use PhpParser\Node;
17
use PhpParser\NodeVisitorAbstract;
18
19
use function Cycle\ORM\Promise\inject;
20
21
/**
22
 * Add resolver property
23
 */
24
final class AddResolverProperty extends NodeVisitorAbstract
25
{
26
    /** @var string */
27
    private $property;
28
29
    /** @var string */
30
    private $type;
31
32
    /** @var string */
33
    private $class;
34
35
    /**
36
     * @param string $property
37
     * @param string $type
38
     * @param string $class
39
     */
40
    public function __construct(string $property, string $type, string $class)
41
    {
42
        $this->property = $property;
43
        $this->type = $type;
44
        $this->class = $class;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 View Code Duplication
    public function leaveNode(Node $node)
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...
51
    {
52
        if ($node instanceof Node\Stmt\Class_) {
53
            $node->stmts = inject(
54
                $node->stmts,
55
                Node\Stmt\ClassMethod::class,
56
                [$this->buildProperty()]
57
            );
58
        }
59
60
        return null;
61
    }
62
63
    /**
64
     * @return Node\Stmt\Property
65
     */
66
    private function buildProperty(): Node\Stmt\Property
67
    {
68
        $property = new Property($this->property);
69
        $property->makePrivate();
70
        $property->setDocComment(PHPDoc::writeProperty("{$this->type}|{$this->class}"));
71
72
        return $property->getNode();
73
    }
74
}
75