• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

liip / LiipImagineBundle / 10701363663

04 Sep 2024 12:11PM UTC coverage: 81.688% (-0.06%) from 81.746%
10701363663

push

github

web-flow
Merge pull request #1610 from liip/cs-fix

apply latest cs fixer

67 of 84 new or added lines in 42 files covered. (79.76%)

2 existing lines in 1 file now uncovered.

2275 of 2785 relevant lines covered (81.69%)

103.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/Binary/Loader/FlysystemLoader.php
1
<?php
2

3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11

12
namespace Liip\ImagineBundle\Binary\Loader;
13

14
use League\Flysystem\FilesystemInterface;
15
use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
16
use Liip\ImagineBundle\Exception\InvalidArgumentException;
17
use Liip\ImagineBundle\Model\Binary;
18
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface as DeprecatedExtensionGuesserInterface;
19
use Symfony\Component\Mime\MimeTypesInterface;
20

21
class FlysystemLoader implements LoaderInterface
22
{
23
    /**
24
     * @var FilesystemInterface
25
     */
26
    protected $filesystem;
27

28
    /**
29
     * @var MimeTypesInterface|DeprecatedExtensionGuesserInterface
30
     */
31
    protected $extensionGuesser;
32

33
    public function __construct(
34
        $extensionGuesser,
35
        FilesystemInterface $filesystem)
36
    {
37
        if (!$extensionGuesser instanceof MimeTypesInterface && !$extensionGuesser instanceof DeprecatedExtensionGuesserInterface) {
8✔
38
            throw new InvalidArgumentException('$extensionGuesser must be an instance of Symfony\Component\Mime\MimeTypesInterface or Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface');
2✔
39
        }
40

41
        if (interface_exists(MimeTypesInterface::class) && $extensionGuesser instanceof DeprecatedExtensionGuesserInterface) {
6✔
NEW
42
            @trigger_error(\sprintf('Passing a %s to "%s()" is deprecated since Symfony 4.3, pass a "%s" instead.', DeprecatedExtensionGuesserInterface::class, __METHOD__, MimeTypesInterface::class), E_USER_DEPRECATED);
×
43
        }
44

45
        $this->extensionGuesser = $extensionGuesser;
6✔
46
        $this->filesystem = $filesystem;
6✔
47
    }
3✔
48

49
    public function find($path)
50
    {
51
        if (false === $this->filesystem->has($path)) {
4✔
52
            throw new NotLoadableException(\sprintf('Source image "%s" not found.', $path));
2✔
53
        }
54

55
        $mimeType = $this->filesystem->getMimetype($path);
2✔
56

57
        $extension = $this->getExtension($mimeType);
2✔
58

59
        return new Binary(
2✔
60
            $this->filesystem->read($path),
2✔
61
            $mimeType,
2✔
62
            $extension
2✔
63
        );
1✔
64
    }
65

66
    private function getExtension(?string $mimeType): ?string
67
    {
68
        if ($this->extensionGuesser instanceof DeprecatedExtensionGuesserInterface) {
2✔
69
            return $this->extensionGuesser->guess($mimeType);
×
70
        }
71

72
        if (null === $mimeType) {
2✔
73
            return null;
×
74
        }
75

76
        return $this->extensionGuesser->getExtensions($mimeType)[0] ?? null;
2✔
77
    }
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc