Completed
Pull Request — master (#732)
by 12345
03:41
created

FlysystemLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 2 Features 2
Metric Value
wmc 3
c 5
b 2
f 2
lcom 1
cbo 3
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A find() 0 14 2
1
<?php
2
3
namespace Liip\ImagineBundle\Binary\Loader;
4
5
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
6
use Liip\ImagineBundle\Model\Binary;
7
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
8
use League\Flysystem\FilesystemInterface;
9
10
class FlysystemLoader implements LoaderInterface
11
{
12
    /**
13
     * @var FilesystemInterface
14
     */
15
    protected $filesystem;
16
17
    /**
18
     * @var ExtensionGuesserInterface
19
     */
20
    protected $extensionGuesser;
21
22
    public function __construct(
23
        ExtensionGuesserInterface $extensionGuesser,
24
        FilesystemInterface $filesystem)
25
    {
26
        $this->extensionGuesser = $extensionGuesser;
27
        $this->filesystem = $filesystem;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function find($path)
34
    {
35
        if ($this->filesystem->has($path) === false) {
36
            throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
37
        }
38
39
        $mimeType = $this->filesystem->getMimetype($path);
40
41
        return new Binary(
42
            $this->filesystem->read($path),
43
            $mimeType,
44
            $this->extensionGuesser->guess($mimeType)
45
        );
46
    }
47
}
48