1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pinq\Expressions; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* <code> |
7
|
|
|
* Class::Method('foo') |
8
|
|
|
* </code> |
9
|
|
|
* |
10
|
|
|
* @author Elliot Levin <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class StaticMethodCallExpression extends StaticClassExpression |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Expression |
16
|
|
|
*/ |
17
|
|
|
private $name; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ArgumentExpression[] |
21
|
|
|
*/ |
22
|
|
|
private $arguments; |
23
|
|
|
|
24
|
|
|
public function __construct(Expression $class, Expression $name, array $arguments = []) |
25
|
|
|
{ |
26
|
|
|
parent::__construct($class); |
27
|
|
|
$this->name = $name; |
28
|
|
|
$this->arguments = self::verifyAll($arguments, ArgumentExpression::getType()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return Expression |
33
|
|
|
*/ |
34
|
|
|
public function getName() |
35
|
|
|
{ |
36
|
|
|
return $this->name; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return ArgumentExpression[] |
41
|
|
|
*/ |
42
|
|
|
public function getArguments() |
43
|
|
|
{ |
44
|
|
|
return $this->arguments; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function traverse(ExpressionWalker $walker) |
48
|
|
|
{ |
49
|
|
|
return $walker->walkStaticMethodCall($this); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Expression $class |
54
|
|
|
* @param Expression $name |
55
|
|
|
* @param ArgumentExpression[] $arguments |
56
|
|
|
* |
57
|
|
|
* @return self |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function update(Expression $class, Expression $name, array $arguments = []) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
if ($this->class === $class |
62
|
|
|
&& $this->name === $name |
63
|
|
|
&& $this->arguments === $arguments |
64
|
|
|
) { |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return new self($class, $name, $arguments); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
protected function compileMember(&$code) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
if ($this->name instanceof ValueExpression) { |
74
|
|
|
$code .= $this->name->getValue(); |
75
|
|
|
} else { |
76
|
|
|
$this->name->compileCode($code); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$code .= '('; |
80
|
|
|
$code .= implode(',', self::compileAll($this->arguments)); |
81
|
|
|
$code .= ')'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function updateClassValue(Expression $class) |
85
|
|
|
{ |
86
|
|
|
return new self($class, $this->name, $this->arguments); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function dataToSerialize() |
90
|
|
|
{ |
91
|
|
|
return [$this->name, $this->arguments]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function unserializeData($data) |
95
|
|
|
{ |
96
|
|
|
list($this->name, $this->arguments) = $data; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function __clone() |
100
|
|
|
{ |
101
|
|
|
$this->class = clone $this->class; |
102
|
|
|
$this->name = clone $this->name; |
103
|
|
|
$this->arguments = self::cloneAll($this->arguments); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.