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.

Background   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 55
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A apply() 0 20 2
1
<?php
2
namespace HtImgModule\Imagine\Filter;
3
4
use Imagine\Filter\FilterInterface;
5
use Imagine\Image\ImageInterface;
6
use Imagine\Image\ImagineInterface;
7
use Imagine\Image\Box;
8
use Imagine\Image\Point;
9
10
class Background implements FilterInterface
11
{
12
    /**
13
     * @var ImagineInterface
14
     */
15
    protected $imagine;
16
17
    /**
18
     * @var array|int[]
19
     */
20
    protected $size;
21
22
    /**
23
     * @var string
24
     */
25
    protected $color;
26
27
    /**
28
     * Constructor
29
     *
30
     * @param ImagineInterface $imagine
31
     * @param array|int[]      $size
32
     * @param string           $color
33
     */
34 3
    public function __construct(ImagineInterface $imagine, $size = null, $color = '#fff')
35
    {
36 3
        $this->imagine  = $imagine;
37 3
        $this->size     = $size;
0 ignored issues
show
Documentation Bug introduced by
It seems like $size can be null. However, the property $size is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
38 3
        $this->color    = $color;
39 3
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 2
    public function apply(ImageInterface $image)
45
    {
46 2
        if ($this->size) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->size of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
47 2
            list($width, $height) = $this->size;
48
49 2
            $size = new Box($width, $height);
50 2
            $topLeft = new Point(
51 2
                ($width - $image->getSize()->getWidth()) / 2,
52 2
                ($height - $image->getSize()->getHeight()) / 2
53
            );
54
        } else {
55 1
            $topLeft = new Point(0, 0);
56 1
            $size = $image->getSize();
57
        }
58
59 2
        $background = $image->palette()->color($this->color);
60 2
        $canvas = $this->imagine->create($size, $background);
61
62 2
        return $canvas->paste($image, $topLeft);
63
    }
64
}
65