1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Patsura Dmitry https://github.com/ovr <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace PHPSA\Definition; |
7
|
|
|
|
8
|
|
|
use PHPSA\CompiledExpression; |
9
|
|
|
use PHPSA\Context; |
10
|
|
|
use PhpParser\Node; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class FunctionDefinition |
14
|
|
|
* @package PHPSA\Definition |
15
|
|
|
*/ |
16
|
|
|
class ClosureDefinition extends ParentDefinition |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @todo Use Finder |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $filepath; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Node\Stmt\Function_ |
27
|
|
|
*/ |
28
|
|
|
protected $statement; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $returnTypes = CompiledExpression::MIXED; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $possibleReturnTypes = array(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param $name |
42
|
|
|
*/ |
43
|
|
|
public function __construct(Node\Expr\Closure $statement) |
44
|
|
|
{ |
45
|
|
|
$this->statement = $statement; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Compile function to check it |
50
|
|
|
* |
51
|
|
|
* @param Context $context |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
|
|
public function compile(Context $context) |
55
|
|
|
{ |
56
|
|
|
if ($this->compiled) { |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$context->setFilepath($this->filepath); |
61
|
|
|
$this->compiled = true; |
62
|
|
|
|
63
|
|
|
$context->scopePointer = $this->getPointer(); |
64
|
|
|
$context->setScope(null); |
65
|
|
|
|
66
|
|
|
if (count($this->statement->stmts) == 0) { |
67
|
|
|
return $context->notice( |
68
|
|
|
'not-implemented-function', |
69
|
|
|
sprintf('Function %s() is not implemented', $this->name), |
70
|
|
|
$this->statement |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (count($this->statement->params) > 0) { |
75
|
|
|
/** @var Node\Param $parameter */ |
76
|
|
|
foreach ($this->statement->params as $parameter) { |
77
|
|
|
$context->addSymbol($parameter->name); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
foreach ($this->statement->stmts as $st) { |
82
|
|
|
\PHPSA\nodeVisitorFactory($st, $context); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getFilepath() |
92
|
|
|
{ |
93
|
|
|
return $this->filepath; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $filepath |
98
|
|
|
*/ |
99
|
|
|
public function setFilepath($filepath) |
100
|
|
|
{ |
101
|
|
|
$this->filepath = $filepath; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function getNamespace() |
108
|
|
|
{ |
109
|
|
|
return $this->namespace; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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..