Skip to content

Commit fea0d65

Browse files
author
Greg Bowler
authored
Make getFile consistent with other functions (#298)
* feature: make getFile consistently nullable closes #287 * build: php 8.1 compatibility * build: cache php version * build: fix dependency versions * ci: use phpunit composer version * build: php 8.1 compatibility * ci: upgrade steps * ci: name build artifact * ci: hard code version * test: update phpdoc * ci: use v4 upload/download artifact * ci: tag coverage data with sha * ci: tag coverage run number * ci: tag coverage matrix build * ci: typo * ci: upgrade coverage version * ci: add php version to coverage information * ci: add codecov token * feature: make getFile consistently nullable closes #287
1 parent c237ca1 commit fea0d65

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/InputValueGetter.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ public function getMultipleBool(string $key):array {
6969
}
7070

7171

72-
public function getFile(string $key):FileUpload {
72+
public function getFile(string $key):?FileUpload {
7373
/** @var FileUploadInputData|InputDatum[] $params */
7474
$params = $this->fileUploadParameters ?? $this->parameters;
7575

76-
try {
77-
/** @var MultipleInputDatum|FileUpload $file */
78-
$file = $params[$key];
76+
/** @var MultipleInputDatum|FileUpload|null $file */
77+
$file = $params[$key] ?? null;
7978

79+
if(is_null($file)) {
80+
return null;
81+
}
82+
83+
try {
8084
if($file instanceof MultipleInputDatum) {
8185
return $file->current();
8286
}

test/phpunit/InputTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public function testGetFileFieldSingle(array $get, array $post):void {
121121
);
122122
}
123123

124+
public function testGetFile_null():void {
125+
$input = new Input([], [], []);
126+
$file = $input->getFile("exampleFile");
127+
self::assertNull($file);
128+
}
129+
124130
/** @dataProvider dataRandomGetPost */
125131
public function testGetInvalidDataType(array $get, array $post):void {
126132
self::expectException(InvalidInputMethodException::class);

0 commit comments

Comments
 (0)