FlysystemDataLoader::find()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 14
ccs 0
cts 7
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Imagine;
15
16
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
17
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
18
use Liip\ImagineBundle\Model\Binary;
19
use Silverback\ApiComponentsBundle\Flysystem\FilesystemProvider;
20
use Symfony\Component\Mime\MimeTypes;
21
22
/**
23
 * @author Daniel West <[email protected]>
24
 */
25
class FlysystemDataLoader implements LoaderInterface
26
{
27
    protected FilesystemProvider $filesystemProvider;
28
    private ?string $adapter = null;
29
30
    public function __construct(FilesystemProvider $filesystemProvider)
31
    {
32
        $this->filesystemProvider = $filesystemProvider;
33
    }
34
35
    public function setAdapter(?string $adapter): void
36
    {
37
        $this->adapter = $adapter;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function find($path): Binary
44
    {
45
        $filesystem = $this->filesystemProvider->getFilesystem($this->adapter);
0 ignored issues
show
Bug introduced by
It seems like $this->adapter can also be of type null; however, parameter $name of Silverback\ApiComponents...ovider::getFilesystem() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $filesystem = $this->filesystemProvider->getFilesystem(/** @scrutinizer ignore-type */ $this->adapter);
Loading history...
46
47
        // This should be finding the file that we have uploaded into a location already - source file locator
48
        if (false === $filesystem->fileExists($path)) {
49
            throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
50
        }
51
52
        $mimeType = $filesystem->mimeType($path);
53
54
        $extension = MimeTypes::getDefault()->getExtensions($mimeType)[0];
55
56
        return new Binary($filesystem->read($path), $mimeType, $extension);
57
    }
58
}
59