Skip to content

Commit f6a7e05

Browse files
author
May Meow
committed
Fix CS-Check and Stan Errors
1 parent dcfbc80 commit f6a7e05

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace FileUpload\Exceptions;
5+
6+
use Throwable;
7+
8+
class FileContentException extends \Exception
9+
{
10+
/**
11+
* @param string $message Message
12+
* @param int $code Exception code
13+
* @param \Throwable|null $previous The previous throwable used for the exception chaining.
14+
*/
15+
public function __construct($message = 'Cannot load content of file', $code = 1, ?Throwable $previous = null)
16+
{
17+
parent::__construct($message, $code, $previous);
18+
}
19+
}

src/File/UploadedFile.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,65 @@
55

66
class UploadedFile implements StoredFileInterface
77
{
8+
/**
9+
* @var string $fileName
10+
*/
811
protected $fileName;
912

13+
/**
14+
* @var string $path
15+
*/
1016
protected $path;
1117

18+
/**
19+
* @var string $storageType
20+
*/
1221
protected $storageType;
1322

23+
/**
24+
* @var string $fileType
25+
*/
1426
protected $fileType;
1527

28+
/**
29+
* @var string $fileContent
30+
*/
1631
protected $fileContent;
1732

1833
/**
19-
* @return mixed
34+
* @return string
2035
*/
2136
public function getFileName(): string
2237
{
2338
return $this->fileName;
2439
}
2540

2641
/**
27-
* @param mixed $fileName File name
42+
* @param string $fileName File name
2843
* @return void
2944
*/
3045
public function setFileName($fileName): void
3146
{
3247
$this->fileName = $fileName;
3348

49+
/** @var string[] $pathInfo */
3450
$pathInfo = pathinfo($fileName);
3551
$this->fileType = $pathInfo['extension'];
3652
}
3753

3854
/**
39-
* @return mixed
55+
* @return string
4056
*/
4157
public function getPath(): string
4258
{
4359
return $this->path;
4460
}
4561

4662
/**
47-
* @param mixed $path Path to file without filename
63+
* @param string $path Path to file without filename
4864
* @return void
4965
*/
50-
public function setPath($path): void
66+
public function setPath(string $path): void
5167
{
5268
$this->path = $path;
5369
}
@@ -70,7 +86,7 @@ public function setStorageType(string $storageType): void
7086
}
7187

7288
/**
73-
* @return mixed
89+
* @return string
7490
*/
7591
public function getFileType(): string
7692
{

src/Storage/LocalStorageManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace FileUpload\Storage;
55

6+
use FileUpload\Exceptions\FileContentException;
67
use FileUpload\File\StoredFileInterface;
78
use FileUpload\File\UploadedFile;
89
use Psr\Http\Message\UploadedFileInterface;
@@ -45,11 +46,16 @@ public function put(UploadedFileInterface $fileObject): StoredFileInterface
4546
*
4647
* @param string $fileName Filename without slashes
4748
* @return \FileUpload\File\StoredFileInterface
49+
* @throws \FileUpload\Exceptions\FileContentException
4850
*/
4951
public function pull(string $fileName): StoredFileInterface
5052
{
5153
$fileContent = file_get_contents($this->configuration->getConfig('storagePath') . $fileName);
5254

55+
if ($fileContent == false) {
56+
throw new FileContentException();
57+
}
58+
5359
$uploadedFile = new UploadedFile();
5460
$uploadedFile->setFileName($fileName);
5561
$uploadedFile->setPath($this->configuration->getConfig('storagePath'));

0 commit comments

Comments
 (0)