1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Funivan\PhpTokenizer\Pattern\Patterns; |
4
|
|
|
|
5
|
|
|
use Funivan\PhpTokenizer\Pattern\PatternMatcher; |
6
|
|
|
use Funivan\PhpTokenizer\Query\Query; |
7
|
|
|
use Funivan\PhpTokenizer\QuerySequence\QuerySequence; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
class FunctionCallPattern implements PatternInterface { |
13
|
|
|
|
14
|
|
|
const OUTPUT_FULL = 1; |
15
|
|
|
|
16
|
|
|
const OUTPUT_ARGUMENTS = 2; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Query|null |
20
|
|
|
*/ |
21
|
|
|
private $nameQuery; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ArgumentsPattern |
25
|
|
|
*/ |
26
|
|
|
private $parametersPattern; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ArgumentsPattern |
30
|
|
|
*/ |
31
|
|
|
private $outputType = self::OUTPUT_FULL; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return $this |
36
|
|
|
*/ |
37
|
3 |
|
public function outputFull() { |
38
|
3 |
|
$this->outputType = self::OUTPUT_FULL; |
|
|
|
|
39
|
3 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
3 |
|
public function outputArguments() { |
47
|
3 |
|
$this->outputType = self::OUTPUT_ARGUMENTS; |
|
|
|
|
48
|
3 |
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Query $query |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
2 |
|
public function withName(Query $query) { |
57
|
2 |
|
$this->nameQuery = $query; |
58
|
2 |
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param ArgumentsPattern $pattern |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
3 |
|
public function withParameters(ArgumentsPattern $pattern) { |
67
|
3 |
|
$this->parametersPattern = $pattern; |
68
|
3 |
|
return $this; |
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
9 |
|
public function __invoke(QuerySequence $querySequence) { |
76
|
|
|
|
77
|
8 |
|
$name = $querySequence->strict(T_STRING); |
78
|
8 |
|
if ($this->nameQuery !== null and $this->nameQuery->isValid($name) === false) { |
79
|
2 |
|
return null; |
80
|
|
|
} |
81
|
|
|
|
82
|
8 |
|
$querySequence->possible(T_WHITESPACE); |
83
|
8 |
|
$arguments = $querySequence->section('(', ')'); |
84
|
|
|
|
85
|
8 |
|
if (!$querySequence->isValid()) { |
86
|
8 |
|
return null; |
87
|
|
|
} |
88
|
|
|
|
89
|
8 |
|
$querySequence->moveToToken($name); |
90
|
8 |
|
$before = $querySequence->move(-1); |
91
|
8 |
|
if ($before->getType() === T_WHITESPACE) { |
92
|
8 |
|
$before = $querySequence->move(-1); |
93
|
8 |
|
} |
94
|
|
|
|
95
|
8 |
|
if (in_array($before->getValue(), ['::', 'function', '->'])) { |
96
|
2 |
|
return null; |
97
|
|
|
} |
98
|
|
|
|
99
|
8 |
|
if ($this->parametersPattern !== null) { |
100
|
2 |
|
$pattern = (new PatternMatcher($arguments))->apply($this->parametersPattern); |
101
|
2 |
|
if (count($pattern->getCollections()) === 0) { |
102
|
3 |
|
return null; |
103
|
|
|
} |
104
|
2 |
|
} |
105
|
|
|
|
106
|
9 |
|
if ($this->outputType === self::OUTPUT_ARGUMENTS) { |
107
|
2 |
|
return $arguments; |
108
|
|
|
} |
109
|
|
|
|
110
|
6 |
|
return $querySequence->getCollection()->extractByTokens($name, $arguments->getLast()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..