1 | <?php |
||
19 | class IP implements ExcluderInterface |
||
20 | { |
||
21 | /** |
||
22 | * List of IPs to be excluded. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $ips = []; |
||
27 | |||
28 | /** |
||
29 | * Allowed proxies. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $trustedProxies = []; |
||
34 | |||
35 | /** |
||
36 | * IP constructor. |
||
37 | * |
||
38 | * @param string|array $ips |
||
|
|||
39 | * @param string|array $trustedProxies |
||
40 | * |
||
41 | * @throws \InvalidArgumentException |
||
42 | */ |
||
43 | public function __construct($ips = null, $trustedProxies = null) |
||
65 | |||
66 | /** |
||
67 | * Add IP. |
||
68 | * |
||
69 | * @param string $ipAddress |
||
70 | * |
||
71 | * @throws \InvalidArgumentException |
||
72 | * |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function addIP($ipAddress) |
||
87 | |||
88 | /** |
||
89 | * Add Trusted proxy. |
||
90 | * |
||
91 | * @param string $ipAddress |
||
92 | * |
||
93 | * @throws \InvalidArgumentException |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function addTrustedProxy($ipAddress) |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | * |
||
113 | * @throws \RuntimeException |
||
114 | */ |
||
115 | public function isExcluded(ServerRequestInterface $request) |
||
131 | |||
132 | /** |
||
133 | * Find client's IP. |
||
134 | * |
||
135 | * @param ServerRequestInterface $request |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | protected function determineCurrentIP(ServerRequestInterface $request) |
||
171 | |||
172 | /** |
||
173 | * Return current IP retrieved from server parameters. |
||
174 | * |
||
175 | * @param ServerRequestInterface $request |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | private function getIPFromServerParams(ServerRequestInterface $request) |
||
190 | |||
191 | /** |
||
192 | * Check IP validity. |
||
193 | * |
||
194 | * @param string $ipAddress |
||
195 | * |
||
196 | * @return bool |
||
197 | */ |
||
198 | private function isValidIP($ipAddress) |
||
202 | } |
||
203 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
array
and suggests a stricter type likearray<String>
.Most often this is a case of a parameter that can be null in addition to its declared types.