1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the pinepain/php-v8-js-sandbox PHP library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Licensed under the MIT license: http://opensource.org/licenses/MIT |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the |
11
|
|
|
* LICENSE file that was distributed with this source or visit |
12
|
|
|
* http://opensource.org/licenses/MIT |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
namespace Pinepain\JsSandbox\Specs; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use Pinepain\JsSandbox\Specs\Parameters\ParameterSpecInterface; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class ParametersList implements ParametersListInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
private $number_of_parameters = 0; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
private $number_of_required_parameters = 0; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
private $variadic = false; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ParameterSpecInterface[] |
41
|
|
|
*/ |
42
|
|
|
private $parameters; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ParameterSpecInterface[] ...$parameters |
46
|
|
|
*/ |
47
|
9 |
|
public function __construct(ParameterSpecInterface ...$parameters) |
48
|
|
|
{ |
49
|
9 |
|
$this->parameters = $parameters; |
|
|
|
|
50
|
|
|
|
51
|
9 |
|
$this->number_of_parameters = $this->getNumberOfParametersFromArray($parameters); |
|
|
|
|
52
|
9 |
|
$this->number_of_required_parameters = $this->getNumberOfRequiredParametersFromArray($parameters); |
|
|
|
|
53
|
9 |
|
$this->variadic = $this->getIsVariadicFromArray($parameters); |
|
|
|
|
54
|
9 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getNumberOfParameters(): int |
60
|
|
|
{ |
61
|
|
|
return $this->number_of_parameters; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function getNumberOfRequiredParameters(): int |
68
|
|
|
{ |
69
|
|
|
return $this->number_of_required_parameters; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function isVariadic(): bool |
76
|
|
|
{ |
77
|
|
|
return $this->variadic; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
1 |
|
public function getParameters(): array |
84
|
|
|
{ |
85
|
1 |
|
return $this->parameters; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param ParameterSpecInterface[] $parameters |
90
|
|
|
* |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
9 |
|
protected function getNumberOfParametersFromArray(array $parameters): int |
94
|
|
|
{ |
95
|
9 |
|
return count($parameters); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param ParameterSpecInterface[] $parameters |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
9 |
|
protected function getNumberOfRequiredParametersFromArray(array $parameters): int |
104
|
|
|
{ |
105
|
9 |
|
$required = 0; |
106
|
|
|
|
107
|
9 |
|
foreach ($parameters as $p) { |
108
|
1 |
|
if ($p->isOptional() || $p->isVariadic()) { |
109
|
|
|
break; |
110
|
|
|
} |
111
|
|
|
|
112
|
1 |
|
$required++; |
113
|
|
|
} |
114
|
|
|
|
115
|
9 |
|
return $required; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param ParameterSpecInterface[] $parameters |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
9 |
|
protected function getIsVariadicFromArray(array $parameters): bool |
124
|
|
|
{ |
125
|
9 |
|
foreach ($parameters as $p) { |
126
|
1 |
|
if ($p->isVariadic()) { |
127
|
1 |
|
return true; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
9 |
|
return false; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
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..