forked from vimeo/psalm
/
MethodReturnTypeProviderEvent.php
148 lines (134 loc) · 3.59 KB
/
MethodReturnTypeProviderEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace Psalm\Plugin\EventHandler\Event;
use PhpParser;
use Psalm\CodeLocation;
use Psalm\Context;
use Psalm\StatementsSource;
use Psalm\Type\Union;
final class MethodReturnTypeProviderEvent
{
/**
* @var StatementsSource
*/
private $source;
/**
* @var string
*/
private $fq_classlike_name;
/**
* @var lowercase-string
*/
private $method_name_lowercase;
/**
* @var Context
*/
private $context;
/**
* @var CodeLocation
*/
private $code_location;
/**
* @var PhpParser\Node\Expr\MethodCall|PhpParser\Node\Expr\StaticCall
*/
private $stmt;
/**
* @var Union[]|null
*/
private $template_type_parameters;
/**
* @var string|null
*/
private $called_fq_classlike_name;
/**
* @var lowercase-string|null
*/
private $called_method_name_lowercase;
/**
* Use this hook for providing custom return type logic. If this plugin does not know what a method should return
* but another plugin may be able to determine the type, return null. Otherwise return a mixed union type if
* something should be returned, but can't be more specific.
*
* @param PhpParser\Node\Expr\MethodCall|PhpParser\Node\Expr\StaticCall $stmt
* @param ?array<Union> $template_type_parameters
* @param lowercase-string $method_name_lowercase
* @param lowercase-string $called_method_name_lowercase
*
* @internal
*/
public function __construct(
StatementsSource $source,
string $fq_classlike_name,
string $method_name_lowercase,
$stmt,
Context $context,
CodeLocation $code_location,
?array $template_type_parameters = null,
?string $called_fq_classlike_name = null,
?string $called_method_name_lowercase = null
) {
$this->source = $source;
$this->fq_classlike_name = $fq_classlike_name;
$this->method_name_lowercase = $method_name_lowercase;
$this->context = $context;
$this->code_location = $code_location;
$this->stmt = $stmt;
$this->template_type_parameters = $template_type_parameters;
$this->called_fq_classlike_name = $called_fq_classlike_name;
$this->called_method_name_lowercase = $called_method_name_lowercase;
}
public function getSource(): StatementsSource
{
return $this->source;
}
public function getFqClasslikeName(): string
{
return $this->fq_classlike_name;
}
/**
* @return lowercase-string
*/
public function getMethodNameLowercase(): string
{
return $this->method_name_lowercase;
}
/**
* @return list<PhpParser\Node\Arg>
*/
public function getCallArgs(): array
{
return $this->stmt->getArgs();
}
public function getContext(): Context
{
return $this->context;
}
public function getCodeLocation(): CodeLocation
{
return $this->code_location;
}
/**
* @return Union[]|null
*/
public function getTemplateTypeParameters(): ?array
{
return $this->template_type_parameters;
}
public function getCalledFqClasslikeName(): ?string
{
return $this->called_fq_classlike_name;
}
/**
* @return lowercase-string|null
*/
public function getCalledMethodNameLowercase(): ?string
{
return $this->called_method_name_lowercase;
}
/**
* @return PhpParser\Node\Expr\MethodCall|PhpParser\Node\Expr\StaticCall
*/
public function getStmt()
{
return $this->stmt;
}
}