Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Sep 19, 2024
1 parent ec6345d commit 25db585
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/BulkyItem/FileItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ private function __construct(
private readonly string $mimeType,
private readonly int $size,
) {
try {
\assert('' !== $this->name, 'Name must not be empty');
\assert('' !== $this->mimeType, 'Mime type must not be empty');
\assert($this->size >= 0, 'File size must not be smaller than 0');
} catch (\AssertionError $e) {
throw new InvalidFileItemException($e->getMessage(), $e->getCode(), $e);
}
$this->assert('' !== $this->name, 'Name must not be empty');
$this->assert('' !== $this->mimeType, 'Mime type must not be empty');
$this->assert($this->size >= 0, 'File size must not be smaller than 0');
}

public function getName(): string
Expand Down Expand Up @@ -88,4 +84,11 @@ public static function fromStream($resource, string $name, string $mimeType, int

return new self($resource, $name, $mimeType, $size);
}

private function assert(bool $condition, string $message): void
{
if (!$condition) {
throw new InvalidFileItemException($message);
}
}
}
2 changes: 1 addition & 1 deletion src/BulkyItem/FileItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(private readonly MimeTypeGuesserInterface|null $mime
public function createFromLocalPath(string $path): FileItem
{
if (!(new Filesystem())->exists($path)) {
throw new \InvalidArgumentException(\sprintf('The file "%s" does not exist.', $path));
throw new InvalidFileItemException(\sprintf('The file "%s" does not exist.', $path));
}

$name = basename($path);
Expand Down

0 comments on commit 25db585

Please sign in to comment.