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 |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
} |
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.