Skip to content

Commit 56530b1

Browse files
committed
🚿
1 parent 9a7f193 commit 56530b1

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/ServerUtil.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
namespace chillerlan\HTTP\Utils;
1313

14-
use Psr\Http\Message\{
15-
ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface,
16-
UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface
17-
};
14+
use Psr\Http\Message\{ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, StreamInterface,
15+
UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface};
1816
use InvalidArgumentException;
1917
use function array_keys, explode, function_exists, is_array, is_file, substr;
2018

@@ -176,15 +174,22 @@ public function createUploadedFileFromSpec(array $value):UploadedFileInterface|a
176174
return self::normalizeNestedFileSpec($value);
177175
}
178176

179-
// not sure if dumb or genius
180-
$stream = is_file($value['tmp_name'])
181-
? $this->streamFactory->createStreamFromFile($value['tmp_name'])
182-
: $this->streamFactory->createStream($value['tmp_name']); // @codeCoverageIgnore
177+
$stream = $this->createStreamFromFile($value['tmp_name']);
183178

184179
return $this->uploadedFileFactory
185180
->createUploadedFile($stream, (int)$value['size'], (int)$value['error'], $value['name'], $value['type']);
186181
}
187182

183+
/** @codeCoverageIgnore */
184+
private function createStreamFromFile(string $file):StreamInterface{
185+
186+
if(is_file($file)){
187+
return $this->streamFactory->createStreamFromFile($file);
188+
}
189+
190+
return $this->streamFactory->createStream($file);
191+
}
192+
188193
/**
189194
* Normalizes an array of file specifications.
190195
*

src/UriUtil.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static function withQueryValue(UriInterface $uri, string $key, string|nul
131131
$replaceQuery = ['=' => '%3D', '&' => '%26'];
132132
$key = strtr($key, $replaceQuery);
133133

134-
$result[] = $value !== null
134+
$result[] = ($value !== null)
135135
? $key.'='.strtr($value, $replaceQuery)
136136
: $key;
137137

0 commit comments

Comments
 (0)