/
DynamicFunctionStorage.php
76 lines (63 loc) · 1.93 KB
/
DynamicFunctionStorage.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
<?php
declare(strict_types=1);
namespace Psalm\Plugin;
use Psalm\Storage\FunctionLikeParameter;
use Psalm\Storage\FunctionStorage;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;
final class DynamicFunctionStorage
{
/**
* Required param list for a function.
*
* @var list<FunctionLikeParameter>
*/
public array $params = [];
/**
* A function return type. Maybe null.
* That means we can infer it in {@see FunctionReturnTypeProviderInterface} hook.
*/
public ?Union $return_type = null;
/**
* A function can have template args or return type.
* Plugin hook must fill all used templates here.
*
* @var list<TTemplateParam>
*/
public array $templates = [];
/**
* Determines if a function can be called with named arguments.
*/
public bool $allow_named_arg_calls = true;
/**
* Function purity.
* If function is pure then plugin hook should set it to true.
*/
public bool $pure = false;
/**
* Determines if a function can be called with a various number of arguments.
*/
public bool $variadic = false;
/**
* @internal
*/
public function toFunctionStorage(string $function_cased_name): FunctionStorage
{
$storage = new FunctionStorage();
$storage->cased_name = $function_cased_name;
$storage->setParams($this->params);
$storage->return_type = $this->return_type;
$storage->allow_named_arg_calls = $this->allow_named_arg_calls;
$storage->pure = $this->pure;
$storage->variadic = $this->variadic;
if (!empty($this->templates)) {
$storage->template_types = [];
foreach ($this->templates as $template) {
$storage->template_types[$template->param_name] = [
$template->defining_class => $template->as
];
}
}
return $storage;
}
}