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 ( 922c90...9c1ffc )
by Freek
9s
created

Manipulations   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 322
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 31
lcom 1
cbo 1
dl 0
loc 322
rs 9.8
c 0
b 0
f 0

29 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A crop() 0 7 1
A orientation() 0 4 1
A focalCrop() 0 7 1
A manualCrop() 0 4 1
A width() 0 4 1
A height() 0 4 1
A fit() 0 7 1
A devicePixelRatio() 0 4 1
A brightness() 0 4 1
A gamma() 0 4 1
A contrast() 0 4 1
A sharpen() 0 4 1
A blur() 0 4 1
A pixelate() 0 4 1
A greyscale() 0 4 1
A sepia() 0 4 1
A background() 0 4 1
A border() 0 4 1
A quality() 0 4 1
A format() 0 4 1
A filter() 0 4 1
A apply() 0 6 1
A removeManipulation() 0 4 1
A hasManipulation() 0 4 1
A getManipulationArgument() 0 8 3
A addManipulation() 0 8 1
A mergeManipulations() 0 6 1
A getManipulationSequence() 0 4 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 \Spatie\Image\ManipulationSequence */
38
    protected $manipulationSequence;
39
40
    public function __construct(array $manipulations = [])
41
    {
42
        $this->manipulationSequence = new ManipulationSequence($manipulations);
43
    }
44
45
    /**
46
     * @param string $orientation
47
     *
48
     * @return static
49
     */
50
    public function orientation(string $orientation)
51
    {
52
        return $this->addManipulation($orientation);
53
    }
54
55
    /**
56
     * @param string $cropMethod
57
     * @param int $width
58
     * @param int $height
59
     *
60
     * @return static
61
     */
62
    public function crop(string $cropMethod, int $width, int $height)
63
    {
64
        return $this
65
            ->addManipulation($cropMethod, 'crop')
66
            ->addManipulation($width, 'width')
67
            ->addManipulation($height, 'height');
68
    }
69
70
    /**
71
     * @param int $width
72
     * @param int $height
73
     * @param int $focalX Crop center X in percent
74
     * @param int $focalY Crop center Y in percent
75
     *
76
     * @return static
77
     */
78
    public function focalCrop(int $width, int $height, $focalX, $focalY)
79
    {
80
        return $this
81
            ->addManipulation("crop-{$focalX}-{$focalY}", 'crop')
82
            ->addManipulation($width, 'width')
83
            ->addManipulation($height, 'height');
84
    }
85
86
    /**
87
     * @param int $width
88
     * @param int $height
89
     * @param int $x
90
     * @param int $y
91
     *
92
     * @return static
93
     */
94
    public function manualCrop(int $width, int $height, int $x, int $y)
95
    {
96
        return $this->addManipulation("{$width},{$height},{$x},{$y}");
97
    }
98
99
    /**
100
     * @param int $width
101
     *
102
     * @return $this
103
     */
104
    public function width(int $width)
105
    {
106
        return $this->addManipulation($width);
107
    }
108
109
    /**
110
     * @param int $height
111
     *
112
     * @return static
113
     */
114
    public function height(int $height)
115
    {
116
        return $this->addManipulation($height);
117
    }
118
119
    /**
120
     * @param string $fitMethod
121
     * @param int $width
122
     * @param int $height
123
     *
124
     * @return static
125
     */
126
    public function fit(string $fitMethod, int $width, int $height)
127
    {
128
        return $this
129
            ->addManipulation($fitMethod, 'fit')
130
            ->addManipulation($width, 'width')
131
            ->addManipulation($height, 'height');
132
    }
133
134
    /**
135
     * @param int $ratio
136
     *
137
     * @return static
138
     */
139
    public function devicePixelRatio(int $ratio)
140
    {
141
        return $this->addManipulation($ratio);
142
    }
143
144
    /**
145
     * @param int $brightness
146
     *
147
     * @return static
148
     */
149
    public function brightness(int $brightness)
150
    {
151
        return $this->addManipulation($brightness);
152
    }
153
154
    /**
155
     * @param float $gamma
156
     *
157
     * @return static
158
     */
159
    public function gamma(float $gamma)
160
    {
161
        return $this->addManipulation($gamma);
162
    }
163
164
    /**
165
     * @param int $contrast
166
     *
167
     * @return static
168
     */
169
    public function contrast(int $contrast)
170
    {
171
        return $this->addManipulation($contrast);
172
    }
173
174
    /**
175
     * @param int $sharpen
176
     *
177
     * @return static
178
     */
179
    public function sharpen(int $sharpen)
180
    {
181
        return $this->addManipulation($sharpen);
182
    }
183
184
    /**
185
     * @param int $blur
186
     *
187
     * @return static
188
     */
189
    public function blur(int $blur)
190
    {
191
        return $this->addManipulation($blur);
192
    }
193
194
    /**
195
     * @param int $pixelate
196
     *
197
     * @return static
198
     */
199
    public function pixelate(int $pixelate)
200
    {
201
        return $this->addManipulation($pixelate);
202
    }
203
204
    /**
205
     * @return static
206
     */
207
    public function greyscale()
208
    {
209
        return $this->filter('greyscale');
210
    }
211
212
    /**
213
     * @return static
214
     */
215
    public function sepia()
216
    {
217
        return $this->filter('sepia');
218
    }
219
220
    /**
221
     * @param string $colorName
222
     *
223
     * @return static
224
     */
225
    public function background(string $colorName)
226
    {
227
        return $this->addManipulation($colorName);
228
    }
229
230
    /**
231
     * @param int $width
232
     * @param string $color
233
     * @param string $borderType
234
     *
235
     * @return static
236
     */
237
    public function border(int $width, string $color, string $borderType = 'overlay')
238
    {
239
        return $this->addManipulation("{$width},{$color},{$borderType}", 'border');
240
    }
241
242
    /**
243
     * @param int $quality
244
     *
245
     * @return static
246
     */
247
    public function quality(int $quality)
248
    {
249
        return $this->addManipulation($quality);
250
    }
251
252
    /**
253
     * @param string $format
254
     *
255
     * @return static
256
     */
257
    public function format(string $format)
258
    {
259
        return $this->addManipulation($format);
260
    }
261
262
    /**
263
     * @param string $filterName
264
     *
265
     * @return static
266
     */
267
    protected function filter(string $filterName)
268
    {
269
        return $this->addManipulation($filterName);
270
    }
271
272
    /**
273
     * @return static
274
     */
275
    public function apply()
276
    {
277
        $this->manipulationSequence->startNewGroup();
278
279
        return $this;
280
    }
281
282
    public function removeManipulation(string $name)
283
    {
284
        $this->manipulationSequence->removeManipulation($name);
285
    }
286
287
    public function hasManipulation(string $manipulationName): bool
288
    {
289
        return ! is_null($this->getManipulationArgument($manipulationName));
290
    }
291
292
    /**
293
     * @param string $manipulationName
294
     *
295
     * @return string|null
296
     */
297
    public function getManipulationArgument(string $manipulationName)
298
    {
299
        foreach ($this->manipulationSequence->getGroups() as $manipulationSet) {
300
            if (array_key_exists($manipulationName, $manipulationSet)) {
301
                return $manipulationSet[$manipulationName];
302
            }
303
        }
304
    }
305
306
    protected function addManipulation(string $manipulationArgument, string $manipulationName = null)
307
    {
308
        $manipulationName = $manipulationName ?? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
309
310
        $this->manipulationSequence->addManipulation($manipulationName, $manipulationArgument);
311
312
        return $this;
313
    }
314
315
    public function mergeManipulations(Manipulations $manipulations)
316
    {
317
        $this->manipulationSequence->merge($manipulations->manipulationSequence);
318
319
        return $this;
320
    }
321
322
    public function getManipulationSequence(): ManipulationSequence
323
    {
324
        return $this->manipulationSequence;
325
    }
326
}
327