Skip to content

Commit 4b60242

Browse files
committed
[PHPStan] Added extra validation of filesize result in BinaryBase\Type
1 parent 25cdd62 commit 4b60242

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib/FieldType/BinaryBase/Type.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Ibexa\Contracts\Core\FieldType\Value as SPIValue;
1212
use Ibexa\Contracts\Core\Persistence\Content\FieldValue as PersistenceValue;
1313
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
14+
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
1415
use Ibexa\Core\Base\Exceptions\InvalidArgumentValue;
1516
use Ibexa\Core\FieldType\FieldType;
1617
use Ibexa\Core\FieldType\Media\Value;
@@ -150,6 +151,8 @@ protected function checkValueStructure(BaseValue $value)
150151
* Attempts to complete the data in $value.
151152
*
152153
* @param \Ibexa\Core\FieldType\BinaryBase\Value $value
154+
*
155+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
153156
*/
154157
protected function completeValue(BaseValue $value)
155158
{
@@ -163,7 +166,14 @@ protected function completeValue(BaseValue $value)
163166
}
164167

165168
if (!isset($value->fileSize)) {
166-
$value->fileSize = filesize($value->inputUri);
169+
$fileSize = filesize($value->inputUri);
170+
if (false === $fileSize) {
171+
throw new InvalidArgumentException(
172+
'$value->inputUri',
173+
'Could not determine file size of ' . $value->inputUri
174+
);
175+
}
176+
$value->fileSize = $fileSize;
167177
}
168178
}
169179

0 commit comments

Comments
 (0)