FlysystemDataLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 32
ccs 0
cts 11
cp 0
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setAdapter() 0 3 1
A find() 0 14 2
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