AddResolverProperty   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 23.53 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 12
loc 51
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A leaveNode() 12 12 2
A buildProperty() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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