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 ( 695fad...b8da23 )
by Freek
02:07 queued 16s
created

Manipulations::getManipulation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Spatie\Image;
4
5
class Manipulations
6
{
7
    const CROP_TOP_LEFT = 'crop-top-left';
8
    const CROP_TOP = 'crop-top';
9
    const CROP_TOP_RIGHT = 'crop-top-right';
10
    const CROP_LEFT = 'crop-left';
11
    const CROP_CENTER = 'crop-center';
12
    const CROP_RIGHT = 'crop-right';
13
    const CROP_BOTTOM_LEFT = 'crop-bottom-left';
14
    const CROP_BOTTOM = 'crop-bottom';
15
    const CROP_BOTTOM_RIGHT = 'crop-bottom-right';
16
17
    const ORIENTATION_AUTO = 'auto';
18
    const ORIENTATION_90 = 90;
19
    const ORIENTATION_180 = 180;
20
    const ORIENTATION_270 = 270;
21
22
    const FIT_CONTAIN = 'contain';
23
    const FIT_MAX = 'max';
24
    const FIT_FILL = 'fill';
25
    const FIT_STRETCH = 'stretch';
26
    const FIT_CROP = 'crop';
27
28
    const BORDER_OVERLAY = 'overlay';
29
    const BORDER_SHRINK = 'shrink';
30
    const BORDER_EXPAND = 'expand';
31
32
    const FORMAT_JPG = 'jpg';
33
    const FORMAT_PJPG = 'pjpg';
34
    const FORMAT_PNG = 'png';
35
    const FORMAT_GIF = 'gif';
36
37
    /** @var array */
38
    protected $manipulations = [];
39
40
    /**
41
     * @param string $orientation
42
     * @return $this
43
     */
44
    public function orientation(string $orientation)
0 ignored issues
show
Unused Code introduced by
The parameter $orientation is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        return $this->setManipulation(func_get_args());
47
    }
48
49
    /**
50
     * @param string $cropMethod
51
     * @param int $width
52
     * @param int $height
53
     * @return $this
54
     *
55
     * @internal param string $method
56
     */
57
    public function crop(string $cropMethod, int $width, int $height)
58
    {
59
        return $this
60
            ->setManipulation($cropMethod, 'crop')
0 ignored issues
show
Documentation introduced by
$cropMethod is of type string, but the function expects a array.

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...
61
            ->setManipulation($width, 'width')
0 ignored issues
show
Documentation introduced by
$width is of type integer, but the function expects a array.

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...
62
            ->setManipulation($height, 'height');
0 ignored issues
show
Documentation introduced by
$height is of type integer, but the function expects a array.

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...
63
    }
64
65
    /**
66
     * @param int $width
67
     *
68
     * @return $this
69
     */
70
    public function width(int $width)
0 ignored issues
show
Unused Code introduced by
The parameter $width is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        return $this->setManipulation(func_get_args());
73
    }
74
75
    /**
76
     * @param int $height
77
     *
78
     * @return $this
79
     */
80
    public function height(int $height)
0 ignored issues
show
Unused Code introduced by
The parameter $height is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        return $this->setManipulation(func_get_args());
83
    }
84
85
    public function fit(string $fitMethod, int $width, int $height)
86
    {
87
        return $this
88
            ->setManipulation($fitMethod, 'fit')
0 ignored issues
show
Documentation introduced by
$fitMethod is of type string, but the function expects a array.

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...
89
            ->setManipulation($width, 'width')
0 ignored issues
show
Documentation introduced by
$width is of type integer, but the function expects a array.

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...
90
            ->setManipulation($height, 'height');
0 ignored issues
show
Documentation introduced by
$height is of type integer, but the function expects a array.

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...
91
    }
92
93
    public function devicePixelRatio(int $ratio)
0 ignored issues
show
Unused Code introduced by
The parameter $ratio is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
    {
95
        return $this->setManipulation(func_get_args());
96
    }
97
98
    public function brightness(int $brightness)
0 ignored issues
show
Unused Code introduced by
The parameter $brightness is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99
    {
100
        return $this->setManipulation(func_get_args());
101
    }
102
103
    public function gamma(float $gamma)
0 ignored issues
show
Unused Code introduced by
The parameter $gamma is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
    {
105
        return $this->setManipulation(func_get_args());
106
    }
107
108
    public function contrast(int $contrast)
0 ignored issues
show
Unused Code introduced by
The parameter $contrast is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109
    {
110
        return $this->setManipulation(func_get_args());
111
    }
112
113
    public function sharpen(int $sharpen)
0 ignored issues
show
Unused Code introduced by
The parameter $sharpen is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115
        return $this->setManipulation(func_get_args());
116
    }
117
118
    public function blur(int $blur)
0 ignored issues
show
Unused Code introduced by
The parameter $blur is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
    {
120
        return $this->setManipulation(func_get_args());
121
    }
122
123
    public function pixelate(int $pixelate)
0 ignored issues
show
Unused Code introduced by
The parameter $pixelate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
124
    {
125
        return $this->setManipulation(func_get_args());
126
    }
127
128
    public function greyscale()
129
    {
130
        return $this->filter('greyscale');
131
    }
132
133
    public function sepia()
134
    {
135
        return $this->filter('sepia');
136
    }
137
138
    public function background(string $colorName)
0 ignored issues
show
Unused Code introduced by
The parameter $colorName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
139
    {
140
        return $this->setManipulation(func_get_args());
141
    }
142
143
    public function border(int $width, string $color, string $borderType = 'overlay')
144
    {
145
        return $this->setManipulation(["{$width},{$color},{$borderType}"], 'border');
146
    }
147
148
    public function quality(int $quality)
0 ignored issues
show
Unused Code introduced by
The parameter $quality is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
    {
150
        return $this->setManipulation(func_get_args());
151
    }
152
153
    public function format(string $format)
0 ignored issues
show
Unused Code introduced by
The parameter $format is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
154
    {
155
        return $this->setManipulation(func_get_args());
156
    }
157
158
    protected function filter(string $filterName)
0 ignored issues
show
Unused Code introduced by
The parameter $filterName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
159
    {
160
        return $this->setManipulation(func_get_args());
161
    }
162
163
    public function hasManipulation($manipulationName): bool
164
    {
165
        return ! is_null($this->getManipulation($manipulationName));
166
    }
167
168
    public function getManipulation($manipulationName): bool
169
    {
170
        foreach($this->manipulations as $manipulation) {
171
            if ($manipulation[0] === $manipulationName) {
172
                return $manipulation;
173
            }
174
        }
175
176
        return null;
177
    }
178
179
180
    protected function setManipulation(array $arguments, string $operation = null)
181
    {
182
        $operation = $operation ?? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
183
184
        $this->manipulations[] = array_merge([$operation], $arguments);
185
186
        return $this;
187
    }
188
189
    public function mergeManipulations(Manipulations $manipulations)
190
    {
191
        $this->manipulations = array_merge($this->manipulations, $manipulations->toArray());
192
193
        return $this;
194
    }
195
196
    public function toArray(): array
197
    {
198
        return $this->manipulations;
199
    }
200
}
201