Skip to content

Commit

Permalink
chore: Minor fixes and cleanup (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel authored Nov 17, 2021
1 parent 96a9a9a commit fc134e9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -429,7 +429,7 @@ public function read($handle, int $chunkSize): string
throw new FileException('Cannot read file.');
}

return (string) $data;
return $data;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function add(...$middleware): self
/**
* Skip middleware.
*
* @param array ...$middleware
* @param array $middleware
*
* @return Middleware
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 3 additions & 3 deletions src/Tus/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -648,7 +648,7 @@ protected function sendPatchRequest(int $bytes, int $offset): int
*
* @param ClientException $e
*
* @return mixed
* @return \Exception
*/
protected function handleClientException(ClientException $e)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Tus/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
1 change: 1 addition & 0 deletions tests/Tus/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit fc134e9

Please sign in to comment.