Skip to content

Commit bfe7c39

Browse files
sudo-plzRoy
andauthored
Prevent possible warnings on unset variables (#542)
Co-authored-by: Roy <rdmartines@vcn.nl>
1 parent 54cff69 commit bfe7c39

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/ServerRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ private static function normalizeNestedFileSpec(array $files = []): array
144144
foreach (array_keys($files['tmp_name']) as $key) {
145145
$spec = [
146146
'tmp_name' => $files['tmp_name'][$key],
147-
'size' => $files['size'][$key],
148-
'error' => $files['error'][$key],
149-
'name' => $files['name'][$key],
150-
'type' => $files['type'][$key],
147+
'size' => $files['size'][$key] ?? null,
148+
'error' => $files['error'][$key] ?? null,
149+
'name' => $files['name'][$key] ?? null,
150+
'type' => $files['type'][$key] ?? null,
151151
];
152152
$normalizedFiles[$key] = self::createUploadedFileFromSpec($spec);
153153
}

tests/ServerRequestTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public function dataNormalizeFiles(): iterable
163163
'tmp_name' => [
164164
0 => '/tmp/php/hp9hskjhf',
165165
1 => '/tmp/php/php1h4j1o',
166+
2 => '/tmp/php/w0ensl4ar',
166167
],
167168
'error' => [
168169
0 => '0',
@@ -173,6 +174,11 @@ public function dataNormalizeFiles(): iterable
173174
1 => '7349',
174175
],
175176
],
177+
'minimum_data' => [
178+
'tmp_name' => [
179+
0 => '/tmp/php/hp9hskjhf',
180+
],
181+
],
176182
'nested' => [
177183
'name' => [
178184
'other' => 'Flag.txt',
@@ -227,6 +233,18 @@ public function dataNormalizeFiles(): iterable
227233
'Image.png',
228234
'image/png'
229235
),
236+
2 => new UploadedFile(
237+
'/tmp/php/w0ensl4ar',
238+
null,
239+
UPLOAD_ERR_OK
240+
),
241+
],
242+
'minimum_data' => [
243+
0 => new UploadedFile(
244+
'/tmp/php/hp9hskjhf',
245+
0,
246+
UPLOAD_ERR_OK
247+
),
230248
],
231249
'nested' => [
232250
'other' => new UploadedFile(

0 commit comments

Comments
 (0)