Passed
Push — master ( d3a94c...76e109 )
by Valentin
05:50
created

UpdatePromiseMethods   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 41
Duplicated Lines 19.51 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 7
dl 8
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A leaveNode() 0 8 3
A ignoreMethod() 8 8 6
A resolvedParentMethodCall() 0 4 1
A resolverCall() 0 4 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
declare(strict_types=1);
3
4
namespace Cycle\ORM\Promise\Visitor;
5
6
use PhpParser\Node;
7
use PhpParser\NodeVisitorAbstract;
8
9
/**
10
 * Modify all accessible methods
11
 */
12
class UpdatePromiseMethods extends NodeVisitorAbstract
13
{
14
    /** @var string */
15
    private $property;
16
17
    public function __construct(string $property)
18
    {
19
        $this->property = $property;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function leaveNode(Node $node)
26
    {
27
        if ($node instanceof Node\Stmt\ClassMethod && !$this->ignoreMethod($node)) {
28
            $node->stmts = [new Node\Stmt\Return_($this->resolvedParentMethodCall($node))];
29
        }
30
31
        return null;
32
    }
33
34 View Code Duplication
    private function ignoreMethod(Node\Stmt\ClassMethod $node): bool
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...
35
    {
36
        if ($node->isPrivate() || $node->isStatic() || $node->isFinal() || $node->isAbstract() || $node->isMagic()) {
37
            return true;
38
        }
39
40
        return false;
41
    }
42
43
    private function resolvedParentMethodCall(Node\Stmt\ClassMethod $node): Node\Expr\MethodCall
44
    {
45
        return new Node\Expr\MethodCall($this->resolverCall(), $node->name->name);
46
    }
47
48
    private function resolverCall(): Node\Expr\PropertyFetch
49
    {
50
        return new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $this->property);
51
    }
52
}