Passed
Push — master ( 327a11...1a5769 )
by Valentin
58s
created

Expressions::resolvePropertyFetch()   A

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 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Cycle\ORM\Promise;
5
6
use PhpParser\Node;
7
8
class Expressions
9
{
10 View Code Duplication
    public static function unsetFunc(string $object, string $property): Node\Stmt\Expression
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...
11
    {
12
        return new Node\Stmt\Expression(
13
            new Node\Expr\FuncCall(
14
                new Node\Name('unset'),
15
                [new Node\Arg(new Node\Expr\PropertyFetch(new Node\Expr\Variable($object), $property))]
16
            )
17
        );
18
    }
19
20 View Code Duplication
    public static function issetFunc(string $object, string $property): Node\Expr\FuncCall
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...
21
    {
22
        return
23
            new Node\Expr\FuncCall(
24
                new Node\Name('isset'),
25
                [new Node\Arg(new Node\Expr\PropertyFetch(new Node\Expr\Variable($object), $property))]
26
27
            );
28
    }
29
30
    public static function inConstArrayFunc(string $name, string $object, string $haystackConst): Node\Expr\FuncCall
31
    {
32
        return new Node\Expr\FuncCall(new Node\Name('in_array'), [
33
                new Node\Arg(new Node\Expr\Variable($name)),
34
                new Node\Arg(new Node\Expr\ClassConstFetch(new Node\Name($object), $haystackConst)),
35
                new Node\Arg(new Node\Expr\ConstFetch(new Node\Name('true')))
36
            ]
37
        );
38
    }
39
40
    public static function resolveIntoVar(string $var, string $object, string $property, string $method): Node\Stmt\Expression
41
    {
42
        return new Node\Stmt\Expression(
43
            new Node\Expr\Assign(
44
                new Node\Expr\Variable($var),
45
                self::resolveMethodCall($object, $property, $method)
46
            )
47
        );
48
    }
49
50
    public static function resolveMethodCall(string $object, string $property, string $method): Node\Expr\MethodCall
51
    {
52
        return new Node\Expr\MethodCall(self::resolvePropertyFetch($object, $property), $method);
53
    }
54
55
    public static function resolvePropertyFetch(string $object, string $property): Node\Expr\PropertyFetch
56
    {
57
        return new Node\Expr\PropertyFetch(new Node\Expr\Variable($object), $property);
58
    }
59
}