GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 037104...b3593d )
by
unknown
10s
created

LoaderManager   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 7
dl 0
loc 95
rs 10
c 0
b 0
f 0
ccs 27
cts 27
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
C loadBinary() 0 29 7
A getExtensionGuesser() 0 8 2
1
<?php
2
namespace HtImgModule\Imagine\Loader;
3
4
use HtImgModule\Binary\Binary;
5
use HtImgModule\Binary\BinaryInterface;
6
use HtImgModule\Exception;
7
use Zend\ServiceManager\ServiceLocatorInterface;
8
use HtImgModule\Imagine\Filter\FilterManagerInterface;
9
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser;
10
use HtImgModule\Binary\MimeTypeGuesser;
11
12
class LoaderManager implements LoaderManagerInterface
13
{
14
    /**
15
     * @var ServiceLocatorInterface
16
     */
17
    protected $imageLoaders;
18
19
    /**
20
     * @var FilterManagerInterface
21
     */
22
    protected $filterManager;
23
24
    /**
25
     * @var string
26
     */
27
    protected $defaultImageLoader;
28
29
    /**
30
     * @var MimeTypeGuesser
31
     */
32
    protected $mimeTypeGuesser;
33
34
    /**
35
     * @var MimeTypeExtensionGuesser
36
     */
37
    protected $extensionGuesser;
38
39
    /**
40
     * Constructor
41
     *
42
     * @param ServiceLocatorInterface $imageLoaders
43
     * @param FilterManagerInterface  $filterManager
44
     * @param string                  $defaultImageLoader
45
     * @param MimeTypeGuesser         $mimeTypeGuesser
46
     */
47 4
    public function __construct(
48
        ServiceLocatorInterface $imageLoaders,
49
        FilterManagerInterface $filterManager,
50
        $defaultImageLoader,
51
        MimeTypeGuesser $mimeTypeGuesser
52
    )
53
    {
54 4
        $this->imageLoaders       = $imageLoaders;
55 4
        $this->filterManager      = $filterManager;
56 4
        $this->defaultImageLoader = $defaultImageLoader;
57 4
        $this->mimeTypeGuesser    = $mimeTypeGuesser;
58 4
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63 3
    public function loadBinary($relativePath, $filter)
64
    {
65 3
        $filterOptions = $this->filterManager->getFilterOptions($filter);
66
67 3
        if (isset($filterOptions['image_loader'])) {
68 2
            $imageLoader = $filterOptions['image_loader'];
69
        } else {
70 1
            $imageLoader = $this->defaultImageLoader;
71
        }
72 3
        if (!is_object($imageLoader)) {
73 2
            $imageLoader = $this->imageLoaders->get(
74 2
                $imageLoader,
75 2
                isset($filterOptions['loader_options']) ? $filterOptions['loader_options'] : []
0 ignored issues
show
Unused Code introduced by
The call to ServiceLocatorInterface::get() has too many arguments starting with isset($filterOptions['lo...der_options'] : array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
76
            );
77
        }
78
79 3
        $binary = $imageLoader->load($relativePath);
80 3
        if (!$binary) {
81 1
            throw new Exception\ImageNotFoundException();
82
        }
83 2
        if (!$binary instanceof BinaryInterface) {
84 2
            $binary = new Binary($binary, $this->mimeTypeGuesser->guess($binary));
85
        }
86 2
        if ($binary->getFormat() === null) {
87 2
            $binary->setFormat($this->getExtensionGuesser()->guess($binary->getMimeType()));
88
        }
89
90 2
        return $binary;
91
    }
92
93
    /**
94
     * Gets a singleton mime type to file extension guesser.
95
     *
96
     * @return MimeTypeExtensionGuesser
97
     */
98 2
    public function getExtensionGuesser()
99
    {
100 2
        if (!$this->extensionGuesser) {
101 2
            $this->extensionGuesser = new MimeTypeExtensionGuesser();
102
        }
103
104 2
        return $this->extensionGuesser;
105
    }
106
}
107