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.

FlysystemLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 16 3
1
<?php
2
namespace HtImgModule\Imagine\Loader;
3
4
use HtImgModule\Binary\Binary;
5
use HtImgModule\Exception;
6
use League\Flysystem\FilesystemInterface;
7
use League\Flysystem\FileNotFoundException;
8
9
/**
10
 * Image Loader for Library, flysystem
11
 * @see https://github.com/thephpleague/flysystem
12
 */
13
class FlysystemLoader implements LoaderInterface
14
{
15
    /**
16
     * @var FilesystemInterface
17
     */
18
    protected $filesystem;
19
20
    /**
21
     * Constructor
22
     *
23
     * @param FilesystemInterface $filesystem
24
     */
25 3
    public function __construct(FilesystemInterface $filesystem)
26
    {
27 3
        $this->filesystem = $filesystem;
28 3
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 3
    public function load($path)
34
    {
35
        try {
36 3
            $contents = $this->filesystem->read($path);
37 1
        } catch (FileNotFoundException $e) {
38 1
            throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $path));
39
        }
40
41 2
        $mimeType = $this->filesystem->getMimeType($path);
42 2
        if ($mimeType === false) {
43
            // Mime Type could not be detected
44 1
            return $contents;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $contents; (false|array) is incompatible with the return type declared by the interface HtImgModule\Imagine\Loader\LoaderInterface::load of type HtImgModule\Binary\Binary|string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
45
        }
46
47 1
        return new Binary($contents, $mimeType);
0 ignored issues
show
Documentation introduced by
$contents is of type false|array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$mimeType is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
    }
49
}
50