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.

GaufretteLoader::load()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
ccs 10
cts 10
cp 1
cc 4
eloc 12
nc 4
nop 1
crap 4
1
<?php
2
namespace HtImgModule\Imagine\Loader;
3
4
use Gaufrette\Filesystem;
5
use Gaufrette\Exception\FileNotFound as FileNotFoundException;
6
use HtImgModule\Exception;
7
use HtImgModule\Binary\Binary;
8
9
/**
10
 * Image Loader for Library, Gaufrette
11
 * @see https://github.com/KnpLabs/Gaufrette
12
 */
13
class GaufretteLoader implements LoaderInterface
14
{
15
    /**
16
     * @var Filesystem
17
     */
18
    protected $filesystem;
19
20
    /**
21
     * Constructor
22
     *
23
     * @param Filesystem $filesystem
24
     */
25 4
    public function __construct(Filesystem $filesystem)
26
    {
27 4
        $this->filesystem = $filesystem;
28 4
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 4
    public function load($path)
34
    {
35
        try {
36 4
            $contents = $this->filesystem->read($path);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->filesystem->read($path); of type string|boolean adds the type boolean to the return on line 45 which is incompatible with the return type declared by the interface HtImgModule\Imagine\Loader\LoaderInterface::load of type HtImgModule\Binary\Binary|string.
Loading history...
37 1
        } catch (FileNotFoundException $e) {
38 1
            throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $path));
39
        }
40
41
        try {
42 3
            $mimeType = $this->filesystem->mimeType($path);
43 1
        } catch (\LogicException $e) {
44
            // Mime Type could not be detected
45 1
            return $contents;
46
        }
47
48 2
        if (!$mimeType) {
49
            // Mime Type could not be detected
50 1
            return $contents;
51
        }
52
53 1
        return new Binary($contents, $mimeType);
0 ignored issues
show
Bug introduced by
It seems like $contents defined by $this->filesystem->read($path) on line 36 can also be of type boolean; however, HtImgModule\Binary\Binary::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
    }
55
}
56