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

UpdatePromiseMethods::ignoreMethod()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.2222
c 0
b 0
f 0
cc 6
nc 2
nop 1
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
}