1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pinq\Expressions; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* <code> |
7
|
|
|
* $I('foo') |
8
|
|
|
* </code> |
9
|
|
|
* |
10
|
|
|
* @author Elliot Levin <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class InvocationExpression extends TraversalExpression |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ArgumentExpression[] |
16
|
|
|
*/ |
17
|
|
|
private $arguments; |
18
|
|
|
|
19
|
|
|
public function __construct(Expression $value, array $arguments) |
20
|
|
|
{ |
21
|
|
|
parent::__construct($value); |
22
|
|
|
$this->arguments = self::verifyAll($arguments, ArgumentExpression::getType()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return ArgumentExpression[] |
27
|
|
|
*/ |
28
|
|
|
public function getArguments() |
29
|
|
|
{ |
30
|
|
|
return $this->arguments; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function traverse(ExpressionWalker $walker) |
34
|
|
|
{ |
35
|
|
|
return $walker->walkInvocation($this); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Expression $value |
40
|
|
|
* @param ArgumentExpression[] $arguments |
41
|
|
|
* |
42
|
|
|
* @return self |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function update(Expression $value, array $arguments) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
if ($this->value === $value |
47
|
|
|
&& $this->arguments === $arguments |
48
|
|
|
) { |
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return new self($value, $arguments); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function updateValueExpression(Expression $value) |
56
|
|
|
{ |
57
|
|
|
return new self($value, $this->arguments); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function compileCode(&$code) |
61
|
|
|
{ |
62
|
|
|
$this->value->compileCode($code); |
63
|
|
|
$code .= '('; |
64
|
|
|
$code .= implode(',', self::compileAll($this->arguments)); |
65
|
|
|
$code .= ')'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function dataToSerialize() |
69
|
|
|
{ |
70
|
|
|
return $this->arguments; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function unserializeData($data) |
74
|
|
|
{ |
75
|
|
|
$this->arguments = $data; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function __clone() |
79
|
|
|
{ |
80
|
|
|
$this->value = clone $this->value; |
81
|
|
|
$this->arguments = self::cloneAll($this->arguments); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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.