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

Expressions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 34.62 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 10
dl 18
loc 52
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A unsetFunc() 9 9 1
A issetFunc() 9 9 1
A inConstArrayFunc() 0 9 1
A resolveIntoVar() 0 9 1
A resolveMethodCall() 0 4 1
A resolvePropertyFetch() 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;
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
}