Completed
Push — 1.0 ( 657f08...d94044 )
by Rob
09:07
created

FileSystemLoader::absolutePathLocate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
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 Liip\ImagineBundle\Binary\Locator\FileSystemLocator;
15
use Liip\ImagineBundle\Binary\Locator\LocatorInterface;
16
use Liip\ImagineBundle\Exception\InvalidArgumentException;
17
use Liip\ImagineBundle\Model\FileBinary;
18
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
19
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
20
21
class FileSystemLoader implements LoaderInterface
22
{
23
    /**
24
     * @var MimeTypeGuesserInterface
25
     */
26
    protected $mimeTypeGuesser;
27
28
    /**
29
     * @var ExtensionGuesserInterface
30
     */
31
    protected $extensionGuesser;
32
33
    /**
34
     * @var LocatorInterface
35
     */
36
    protected $locator;
37
38
    /**
39
     * @param MimeTypeGuesserInterface  $mimeGuesser
40
     * @param ExtensionGuesserInterface $extensionGuesser
41
     * @param string[]                  $dataRoots
42
     * @param LocatorInterface          $locator
0 ignored issues
show
Bug introduced by
There is no parameter named $locator. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
43
     */
44
    public function __construct(
45
        MimeTypeGuesserInterface $mimeGuesser,
46
        ExtensionGuesserInterface $extensionGuesser,
47
        $dataRoots
48
        /* LocatorInterface $locator */
49
    ) {
50
        $this->mimeTypeGuesser = $mimeGuesser;
51
        $this->extensionGuesser = $extensionGuesser;
52
53
        if (count($dataRoots) === 0) {
54
            throw new InvalidArgumentException('One or more data root paths must be specified.');
55
        }
56
57
        if (func_num_args() >= 4 && false === ($this->locator = func_get_arg(3)) instanceof LocatorInterface) {
58
            throw new \InvalidArgumentException(sprintf('Method %s() expects a LocatorInterface for the forth argument.', __METHOD__));
59
        } elseif (func_num_args() < 4) {
60
            @trigger_error(sprintf('Method %s() will have a forth `LocatorInterface $locator` argument in version 2.0. Not defining it is deprecated since version 1.7.2', __METHOD__), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
61
            $this->locator = new FileSystemLocator();
62
        }
63
64
        $this->locator->setOptions(array('roots' => (array) $dataRoots));
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function find($path)
71
    {
72
        $path = $this->locator->locate($path);
73
        $mime = $this->mimeTypeGuesser->guess($path);
74
75
        return new FileBinary($path, $mime, $this->extensionGuesser->guess($mime));
76
    }
77
}
78