1 | <?php |
||||
2 | |||||
3 | namespace Slince\Upload\Filesystem; |
||||
4 | |||||
5 | use League\Flysystem\Filesystem; |
||||
0 ignored issues
–
show
|
|||||
6 | use League\Flysystem\FilesystemException; |
||||
0 ignored issues
–
show
The type
League\Flysystem\FilesystemException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
7 | use RuntimeException; |
||||
8 | use Slince\Upload\File; |
||||
9 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
||||
10 | |||||
11 | class Flysystem implements FilesystemInterface |
||||
12 | { |
||||
13 | /** |
||||
14 | * @var Filesystem |
||||
15 | */ |
||||
16 | protected $filesystem; |
||||
17 | |||||
18 | public function __construct(Filesystem $filesystem) |
||||
19 | { |
||||
20 | $this->filesystem = $filesystem; |
||||
21 | } |
||||
22 | |||||
23 | /** |
||||
24 | * {@inheritdoc} |
||||
25 | */ |
||||
26 | public function upload(string $key, UploadedFile $file, bool $overwrite = false) |
||||
27 | { |
||||
28 | try { |
||||
29 | $this->uploadToFlysystem($key, $file); |
||||
30 | } catch (RuntimeException $exception) { |
||||
31 | if (!$overwrite) { |
||||
32 | throw new RuntimeException(sprintf('The file with key "%s" is exists.', $key)); |
||||
33 | } |
||||
34 | $this->filesystem->delete($key); |
||||
35 | $this->uploadToFlysystem($key, $file); |
||||
36 | } |
||||
37 | @unlink($file->getPathname()); //remove old |
||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
unlink() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||
38 | |||||
39 | return true; |
||||
40 | } |
||||
41 | |||||
42 | /** |
||||
43 | * {@inheritdoc} |
||||
44 | */ |
||||
45 | public function delete(File $file): bool |
||||
46 | { |
||||
47 | $this->filesystem->delete($file->getName()); |
||||
48 | |||||
49 | return true; |
||||
50 | } |
||||
51 | |||||
52 | /** |
||||
53 | * @param string $key |
||||
54 | * @param UploadedFile $file |
||||
55 | * @throws RuntimeException |
||||
56 | */ |
||||
57 | protected function uploadToFlysystem(string $key, UploadedFile $file): void |
||||
58 | { |
||||
59 | try { |
||||
60 | $this->filesystem->writeStream($key, fopen($file->getPathname(), 'r')); |
||||
61 | } catch (FilesystemException $exception) { |
||||
62 | throw new RuntimeException('Failed to upload to flysystem'); |
||||
63 | } |
||||
64 | } |
||||
65 | } |
||||
66 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths