From fc134e9da24b24f061764f0972af3aaa2c068a8b Mon Sep 17 00:00:00 2001 From: Ankit Pokhrel Date: Wed, 17 Nov 2021 11:16:07 +0100 Subject: [PATCH] chore: Minor fixes and cleanup (#365) --- src/Cache/FileStore.php | 4 ++-- src/File.php | 10 +++++----- src/Middleware/Middleware.php | 2 +- src/Request.php | 2 +- src/Response.php | 2 +- src/Tus/Client.php | 6 +++--- src/Tus/Server.php | 4 ++++ tests/Tus/ServerTest.php | 1 + 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Cache/FileStore.php b/src/Cache/FileStore.php index cc2814e..97e77c9 100644 --- a/src/Cache/FileStore.php +++ b/src/Cache/FileStore.php @@ -161,9 +161,9 @@ public function sharedGet(string $path): string * @param string $path * @param string $contents * - * @return int + * @return int|false */ - public function put(string $path, string $contents): int + public function put(string $path, string $contents) { return file_put_contents($path, $contents, LOCK_EX); } diff --git a/src/File.php b/src/File.php index 967a2bd..38b3ca9 100644 --- a/src/File.php +++ b/src/File.php @@ -64,10 +64,10 @@ public function __construct(string $name = null, Cacheable $cache = null) /** * Set file meta. * - * @param int $offset - * @param int $fileSize - * @param string $filePath - * @param string $location + * @param int $offset + * @param int $fileSize + * @param string $filePath + * @param string|null $location * * @return File */ @@ -429,7 +429,7 @@ public function read($handle, int $chunkSize): string throw new FileException('Cannot read file.'); } - return (string) $data; + return $data; } /** diff --git a/src/Middleware/Middleware.php b/src/Middleware/Middleware.php index 49803c7..b261e4d 100644 --- a/src/Middleware/Middleware.php +++ b/src/Middleware/Middleware.php @@ -51,7 +51,7 @@ public function add(...$middleware): self /** * Skip middleware. * - * @param array ...$middleware + * @param array $middleware * * @return Middleware */ diff --git a/src/Request.php b/src/Request.php index 3deabe8..57a16df 100644 --- a/src/Request.php +++ b/src/Request.php @@ -128,7 +128,7 @@ public function extractFileName(): string } /** - * Extracts the meta data from the request header. + * Extracts the metadata from the request header. * * @param string $requestedKey * diff --git a/src/Response.php b/src/Response.php index 3d9ace7..fd897aa 100644 --- a/src/Response.php +++ b/src/Response.php @@ -106,7 +106,7 @@ public function send($content, int $status = HttpResponse::HTTP_OK, array $heade * Create a new file download response. * * @param \SplFileInfo|string $file - * @param string $name + * @param string|null $name * @param array $headers * @param string|null $disposition * diff --git a/src/Tus/Client.php b/src/Tus/Client.php index e5103c7..d771b84 100644 --- a/src/Tus/Client.php +++ b/src/Tus/Client.php @@ -80,8 +80,8 @@ public function __construct(string $baseUri, array $options = []) /** * Set file properties. * - * @param string $file File path. - * @param string $name File name. + * @param string $file File path. + * @param string|null $name File name. * * @return Client */ @@ -648,7 +648,7 @@ protected function sendPatchRequest(int $bytes, int $offset): int * * @param ClientException $e * - * @return mixed + * @return \Exception */ protected function handleClientException(ClientException $e) { diff --git a/src/Tus/Server.php b/src/Tus/Server.php index c57d7aa..2b7ff95 100644 --- a/src/Tus/Server.php +++ b/src/Tus/Server.php @@ -700,6 +700,10 @@ protected function getClientChecksum() */ protected function isExpired($contents): bool { + if (empty($contents)) { + return true; + } + $isExpired = empty($contents['expires_at']) || Carbon::parse($contents['expires_at'])->lt(Carbon::now()); if ($isExpired && $contents['offset'] !== $contents['size']) { diff --git a/tests/Tus/ServerTest.php b/tests/Tus/ServerTest.php index 71838f5..64085e1 100644 --- a/tests/Tus/ServerTest.php +++ b/tests/Tus/ServerTest.php @@ -2840,6 +2840,7 @@ public function it_gets_upload_key_if_already_set(string $key): void */ public function it_checks_expiry_date(): void { + $this->assertTrue($this->tusServerMock->isExpired(null)); $this->assertFalse($this->tusServerMock->isExpired(['expires_at' => 'Sat, 09 Dec 2017 00:00:00 GMT'])); $this->assertFalse($this->tusServerMock->isExpired([