Skip to content

Commit e78e678

Browse files
committed
refactor: clear out phpstan errors in HTTP source and tests
1 parent e3a8f37 commit e78e678

33 files changed

Lines changed: 489 additions & 1126 deletions

system/HTTP/CLIRequest.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ class CLIRequest extends Request
3535
/**
3636
* Stores the segments of our cli "URI" command.
3737
*
38-
* @var array
38+
* @var list<string>
3939
*/
4040
protected $segments = [];
4141

4242
/**
4343
* Command line options and their values.
4444
*
45-
* @var array
45+
* @var array<string, bool|string>
4646
*/
4747
protected $options = [];
4848

4949
/**
5050
* Command line arguments (segments and options).
5151
*
52-
* @var array
52+
* @var array<array-key, bool|string>
5353
*/
5454
protected $args = [];
5555

@@ -101,6 +101,8 @@ public function getPath(): string
101101
/**
102102
* Returns an associative array of all CLI options found, with
103103
* their values.
104+
*
105+
* @return array<string, bool|string>
104106
*/
105107
public function getOptions(): array
106108
{
@@ -109,6 +111,8 @@ public function getOptions(): array
109111

110112
/**
111113
* Returns an array of all CLI arguments (segments and options).
114+
*
115+
* @return array<array-key, bool|string>
112116
*/
113117
public function getArgs(): array
114118
{
@@ -117,6 +121,8 @@ public function getArgs(): array
117121

118122
/**
119123
* Returns the path segments.
124+
*
125+
* @return list<string>
120126
*/
121127
public function getSegments(): array
122128
{
@@ -226,11 +232,11 @@ public function isCLI(): bool
226232
/**
227233
* Fetch an item from GET data.
228234
*
229-
* @param array|string|null $index Index for item to fetch from $_GET.
230-
* @param int|null $filter A filter name to apply.
231-
* @param array|int|null $flags
235+
* @param list<string>|string|null $index Index for item to fetch from $_GET.
236+
* @param int|null $filter A filter name to apply.
237+
* @param array<string, mixed>|int|null $flags
232238
*
233-
* @return array|null
239+
* @return array{}|null
234240
*/
235241
public function getGet($index = null, $filter = null, $flags = null)
236242
{
@@ -240,11 +246,11 @@ public function getGet($index = null, $filter = null, $flags = null)
240246
/**
241247
* Fetch an item from POST.
242248
*
243-
* @param array|string|null $index Index for item to fetch from $_POST.
244-
* @param int|null $filter A filter name to apply
245-
* @param array|int|null $flags
249+
* @param list<string>|string|null $index Index for item to fetch from $_POST.
250+
* @param int|null $filter A filter name to apply
251+
* @param array<string, mixed>|int|null $flags
246252
*
247-
* @return array|null
253+
* @return array{}|null
248254
*/
249255
public function getPost($index = null, $filter = null, $flags = null)
250256
{
@@ -254,11 +260,11 @@ public function getPost($index = null, $filter = null, $flags = null)
254260
/**
255261
* Fetch an item from POST data with fallback to GET.
256262
*
257-
* @param array|string|null $index Index for item to fetch from $_POST or $_GET
258-
* @param int|null $filter A filter name to apply
259-
* @param array|int|null $flags
263+
* @param list<string>|string|null $index Index for item to fetch from $_POST or $_GET
264+
* @param int|null $filter A filter name to apply
265+
* @param array<string, mixed>|int|null $flags
260266
*
261-
* @return array|null
267+
* @return array{}|null
262268
*/
263269
public function getPostGet($index = null, $filter = null, $flags = null)
264270
{
@@ -268,11 +274,11 @@ public function getPostGet($index = null, $filter = null, $flags = null)
268274
/**
269275
* Fetch an item from GET data with fallback to POST.
270276
*
271-
* @param array|string|null $index Index for item to be fetched from $_GET or $_POST
272-
* @param int|null $filter A filter name to apply
273-
* @param array|int|null $flags
277+
* @param list<string>|string|null $index Index for item to be fetched from $_GET or $_POST
278+
* @param int|null $filter A filter name to apply
279+
* @param array<string, mixed>|int|null $flags
274280
*
275-
* @return array|null
281+
* @return array{}|null
276282
*/
277283
public function getGetPost($index = null, $filter = null, $flags = null)
278284
{
@@ -282,21 +288,21 @@ public function getGetPost($index = null, $filter = null, $flags = null)
282288
/**
283289
* This is a place holder for calls from cookie_helper get_cookie().
284290
*
285-
* @param array|string|null $index Index for item to be fetched from $_COOKIE
286-
* @param int|null $filter A filter name to be applied
287-
* @param mixed $flags
291+
* @param list<string>|string|null $index Index for item to be fetched from $_COOKIE
292+
* @param int|null $filter A filter name to be applied
293+
* @param mixed $flags
288294
*
289-
* @return array|null
295+
* @return array{}|null
290296
*/
291297
public function getCookie($index = null, $filter = null, $flags = null)
292298
{
293299
return $this->returnNullOrEmptyArray($index);
294300
}
295301

296302
/**
297-
* @param array|string|null $index
303+
* @param list<string>|string|null $index
298304
*
299-
* @return array|null
305+
* @return array{}|null
300306
*/
301307
private function returnNullOrEmptyArray($index)
302308
{

system/HTTP/CURLRequest.php

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ class CURLRequest extends OutgoingRequest
5151
/**
5252
* The setting values
5353
*
54-
* @var array
54+
* @var array<string, mixed>
5555
*/
5656
protected $config;
5757

5858
/**
5959
* The default setting values
6060
*
61-
* @var array
61+
* @var array<string, mixed>
6262
*/
6363
protected $defaultConfig = [
6464
'timeout' => 0.0,
@@ -71,7 +71,7 @@ class CURLRequest extends OutgoingRequest
7171
* Default values for when 'allow_redirects'
7272
* option is true.
7373
*
74-
* @var array
74+
* @var array<string, mixed>
7575
*/
7676
protected $redirectDefaults = [
7777
'max' => 5,
@@ -92,6 +92,8 @@ class CURLRequest extends OutgoingRequest
9292

9393
/**
9494
* The default options from the constructor. Applied to all requests.
95+
*
96+
* @var array<string, mixed>
9597
*/
9698
private readonly array $defaultOptions;
9799

@@ -156,7 +158,8 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
156158
* Sends an HTTP request to the specified $url. If this is a relative
157159
* URL, it will be merged with $this->baseURI to form a complete URL.
158160
*
159-
* @param string $method HTTP method
161+
* @param string $method HTTP method
162+
* @param array<string, mixed> $options
160163
*/
161164
public function request($method, string $url, array $options = []): ResponseInterface
162165
{
@@ -200,6 +203,8 @@ protected function resetOptions()
200203

201204
/**
202205
* Convenience method for sending a GET request.
206+
*
207+
* @param array<string, mixed> $options
203208
*/
204209
public function get(string $url, array $options = []): ResponseInterface
205210
{
@@ -208,6 +213,8 @@ public function get(string $url, array $options = []): ResponseInterface
208213

209214
/**
210215
* Convenience method for sending a DELETE request.
216+
*
217+
* @param array<string, mixed> $options
211218
*/
212219
public function delete(string $url, array $options = []): ResponseInterface
213220
{
@@ -216,6 +223,8 @@ public function delete(string $url, array $options = []): ResponseInterface
216223

217224
/**
218225
* Convenience method for sending a HEAD request.
226+
*
227+
* @param array<string, mixed> $options
219228
*/
220229
public function head(string $url, array $options = []): ResponseInterface
221230
{
@@ -224,6 +233,8 @@ public function head(string $url, array $options = []): ResponseInterface
224233

225234
/**
226235
* Convenience method for sending an OPTIONS request.
236+
*
237+
* @param array<string, mixed> $options
227238
*/
228239
public function options(string $url, array $options = []): ResponseInterface
229240
{
@@ -232,6 +243,8 @@ public function options(string $url, array $options = []): ResponseInterface
232243

233244
/**
234245
* Convenience method for sending a PATCH request.
246+
*
247+
* @param array<string, mixed> $options
235248
*/
236249
public function patch(string $url, array $options = []): ResponseInterface
237250
{
@@ -240,6 +253,8 @@ public function patch(string $url, array $options = []): ResponseInterface
240253

241254
/**
242255
* Convenience method for sending a POST request.
256+
*
257+
* @param array<string, mixed> $options
243258
*/
244259
public function post(string $url, array $options = []): ResponseInterface
245260
{
@@ -248,6 +263,8 @@ public function post(string $url, array $options = []): ResponseInterface
248263

249264
/**
250265
* Convenience method for sending a PUT request.
266+
*
267+
* @param array<string, mixed> $options
251268
*/
252269
public function put(string $url, array $options = []): ResponseInterface
253270
{
@@ -271,7 +288,8 @@ public function setAuth(string $username, #[SensitiveParameter] string $password
271288
/**
272289
* Set form data to be sent.
273290
*
274-
* @param bool $multipart Set TRUE if you are sending CURLFiles
291+
* @param bool $multipart Set TRUE if you are sending CURLFiles
292+
* @param array<string, mixed> $params
275293
*
276294
* @return $this
277295
*/
@@ -304,6 +322,8 @@ public function setJSON($data)
304322
* Sets the correct settings based on the options array
305323
* passed in.
306324
*
325+
* @param array<string, mixed> $options
326+
*
307327
* @return void
308328
*/
309329
protected function parseOptions(array $options)
@@ -430,6 +450,10 @@ public function send(string $method, string $url)
430450

431451
/**
432452
* Adds $this->headers to the cURL request.
453+
*
454+
* @param array<int, mixed> $curlOptions
455+
*
456+
* @return array<int, mixed>
433457
*/
434458
protected function applyRequestHeaders(array $curlOptions = []): array
435459
{
@@ -450,6 +474,10 @@ protected function applyRequestHeaders(array $curlOptions = []): array
450474

451475
/**
452476
* Apply method
477+
*
478+
* @param array<int, mixed> $curlOptions
479+
*
480+
* @return array<int, mixed>
453481
*/
454482
protected function applyMethod(string $method, array $curlOptions): array
455483
{
@@ -477,6 +505,10 @@ protected function applyMethod(string $method, array $curlOptions): array
477505

478506
/**
479507
* Apply body
508+
*
509+
* @param array<int, mixed> $curlOptions
510+
*
511+
* @return array<int, mixed>
480512
*/
481513
protected function applyBody(array $curlOptions = []): array
482514
{
@@ -491,6 +523,8 @@ protected function applyBody(array $curlOptions = []): array
491523
* Parses the header retrieved from the cURL response into
492524
* our Response object.
493525
*
526+
* @param list<string> $headers
527+
*
494528
* @return void
495529
*/
496530
protected function setResponseHeaders(array $headers = [])
@@ -522,7 +556,10 @@ protected function setResponseHeaders(array $headers = [])
522556
/**
523557
* Set CURL options
524558
*
525-
* @return array
559+
* @param array<int, mixed> $curlOptions
560+
* @param array<string, mixed> $config
561+
*
562+
* @return array<int, mixed>
526563
*
527564
* @throws InvalidArgumentException
528565
*/

system/HTTP/Files/FileCollection.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FileCollection
3131
* Populated the first time either files(), file(), or hasFile()
3232
* is called.
3333
*
34-
* @var array|null
34+
* @var array<string, array<array-key, UploadedFile>|UploadedFile>|null
3535
*/
3636
protected $files;
3737

@@ -40,7 +40,7 @@ class FileCollection
4040
* Each element in the array will be an instance of UploadedFile.
4141
* The key of each element will be the client filename.
4242
*
43-
* @return array|null
43+
* @return array<string, array<array-key, UploadedFile>|UploadedFile>|null
4444
*/
4545
public function all()
4646
{
@@ -167,7 +167,9 @@ protected function populateFiles()
167167
* Given a file array, will create UploadedFile instances. Will
168168
* loop over an array and create objects for each.
169169
*
170-
* @return list<UploadedFile>|UploadedFile
170+
* @param array<string, mixed> $array
171+
*
172+
* @return array<array-key, array<array-key, UploadedFile>|UploadedFile>|UploadedFile
171173
*/
172174
protected function createFileObject(array $array)
173175
{
@@ -203,6 +205,10 @@ protected function createFileObject(array $array)
203205
* of this method.
204206
*
205207
* @see http://php.net/manual/en/reserved.variables.files.php#118294
208+
*
209+
* @param array<string, mixed> $data
210+
*
211+
* @return array<string, mixed>
206212
*/
207213
protected function fixFilesArray(array $data): array
208214
{
@@ -246,8 +252,8 @@ protected function fixFilesArray(array $data): array
246252
/**
247253
* Navigate through an array looking for a particular index
248254
*
249-
* @param array $index The index sequence we are navigating down
250-
* @param array $value The portion of the array to process
255+
* @param list<string> $index The index sequence we are navigating down
256+
* @param array<array-key, array<array-key, UploadedFile>|UploadedFile> $value The portion of the array to process
251257
*
252258
* @return list<UploadedFile>|UploadedFile|null
253259
*/

0 commit comments

Comments
 (0)