Skip to content

Commit

Permalink
Make getFile consistent with other functions (#298)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
g105b authored Apr 25, 2024
1 parent c237ca1 commit fea0d65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/InputValueGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ public function getMultipleBool(string $key):array {
}


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

try {
/** @var MultipleInputDatum|FileUpload $file */
$file = $params[$key];
/** @var MultipleInputDatum|FileUpload|null $file */
$file = $params[$key] ?? null;

if(is_null($file)) {
return null;
}

try {
if($file instanceof MultipleInputDatum) {
return $file->current();
}
Expand Down
6 changes: 6 additions & 0 deletions test/phpunit/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public function testGetFileFieldSingle(array $get, array $post):void {
);
}

public function testGetFile_null():void {
$input = new Input([], [], []);
$file = $input->getFile("exampleFile");
self::assertNull($file);
}

/** @dataProvider dataRandomGetPost */
public function testGetInvalidDataType(array $get, array $post):void {
self::expectException(InvalidInputMethodException::class);
Expand Down

0 comments on commit fea0d65

Please sign in to comment.