AddMagicCloneMethod   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A leaveNode() 0 16 3
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\Builder;
15
use PhpParser\Node;
16
use PhpParser\NodeVisitorAbstract;
17
18
use function Cycle\ORM\Promise\exprClone;
19
20
final class AddMagicCloneMethod extends NodeVisitorAbstract
21
{
22
    /** @var string */
23
    private $resolverProperty;
24
25
    /** @var bool */
26
    private $hasClone;
27
28
    /**
29
     * @param string $resolverProperty
30
     * @param bool   $hasClone
31
     */
32
    public function __construct(string $resolverProperty, bool $hasClone)
33
    {
34
        $this->resolverProperty = $resolverProperty;
35
        $this->hasClone = $hasClone;
36
    }
37
38
    /**
39
     * @param Node $node
40
     * @return int|Node|Node[]|null
41
     */
42
    public function leaveNode(Node $node)
43
    {
44
        if ($this->hasClone) {
45
            return null;
46
        }
47
48
        if ($node instanceof Node\Stmt\Class_) {
49
            $method = new Builder\Method('__clone');
50
            $method->makePublic();
51
            $method->addStmt(exprClone($this->resolverProperty));
52
53
            $node->stmts[] = $method->getNode();
54
        }
55
56
        return null;
57
    }
58
}
59