UpdatePromiseMethods::resolvedParentMethodCall()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 PhpParser\Node;
15
use PhpParser\NodeVisitorAbstract;
16
17
use function Cycle\ORM\Promise\resolvePropertyFetch;
18
19
/**
20
 * Modify all accessible methods
21
 */
22
final class UpdatePromiseMethods extends NodeVisitorAbstract
23
{
24
    /** @var string */
25
    private $property;
26
27
    /**
28
     * @param string $property
29
     */
30
    public function __construct(string $property)
31
    {
32
        $this->property = $property;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function leaveNode(Node $node)
39
    {
40
        if ($node instanceof Node\Stmt\ClassMethod && !$this->ignoreMethod($node)) {
41
            $node->stmts = [new Node\Stmt\Return_($this->resolvedParentMethodCall($node))];
42
        }
43
44
        return null;
45
    }
46
47
    /**
48
     * @param Node\Stmt\ClassMethod $node
49
     * @return bool
50
     */
51
    private function ignoreMethod(Node\Stmt\ClassMethod $node): bool
52
    {
53
        return $node->isPrivate() || $node->isStatic() || $node->isFinal() || $node->isAbstract() || $node->isMagic();
54
    }
55
56
    /**
57
     * @param Node\Stmt\ClassMethod $node
58
     * @return Node\Expr\MethodCall
59
     */
60
    private function resolvedParentMethodCall(Node\Stmt\ClassMethod $node): Node\Expr\MethodCall
61
    {
62
        return new Node\Expr\MethodCall(resolvePropertyFetch('this', $this->property), $node->name->name);
63
    }
64
}
65