1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace JMS\Serializer\Expression; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\ExpressionLanguage\ParsedExpression as BaseExpression; |
8
|
|
|
use Symfony\Component\ExpressionLanguage\SerializedParsedExpression; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Asmir Mustafic <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Expression implements \Serializable |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var BaseExpression |
17
|
|
|
*/ |
18
|
|
|
private $expression; |
19
|
|
|
|
20
|
|
|
public function __construct(BaseExpression $expression) |
21
|
|
|
{ |
22
|
|
|
$this->expression = $expression; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getExpression(): BaseExpression |
26
|
|
|
{ |
27
|
|
|
return $this->expression; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string |
32
|
|
|
* |
33
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint |
34
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation |
35
|
|
|
*/ |
36
|
|
|
public function __toString() |
37
|
|
|
{ |
38
|
|
|
return (string) $this->expression; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
* |
44
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
45
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint |
46
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation |
47
|
|
|
*/ |
48
|
|
|
public function serialize() |
49
|
|
|
{ |
50
|
|
|
return serialize([(string) $this->expression, serialize($this->expression->getNodes())]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $str |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
* |
58
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
59
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint |
60
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation |
61
|
|
|
*/ |
62
|
|
|
public function unserialize($str): void |
63
|
|
|
{ |
64
|
|
|
$this->expression = new SerializedParsedExpression(...unserialize($str)); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function __serialize(): array |
68
|
|
|
{ |
69
|
|
|
return [(string) $this->expression, $this->expression->getNodes()]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function __unserialize(array $data): void |
73
|
|
|
{ |
74
|
|
|
[$expression, $nodes] = $data; |
75
|
|
|
$this->expression = new BaseExpression($expression, $nodes); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.