Pixelate::getPixelate()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.8666
c 0
b 0
f 0
cc 4
nc 3
nop 0
crap 20
1
<?php
2
3
namespace League\Glide\Manipulators;
4
5
use Intervention\Image\Image;
6
7
/**
8
 * @property string $pixel
9
 */
10
class Pixelate extends BaseManipulator
11
{
12
    /**
13
     * Perform pixelate image manipulation.
14
     * @param  Image $image The source image.
15
     * @return Image The manipulated image.
16
     */
17
    public function run(Image $image)
18
    {
19
        $pixelate = $this->getPixelate();
20
21
        if ($pixelate !== null) {
22
            $image->pixelate($pixelate);
23
        }
24
25
        return $image;
26
    }
27
28
    /**
29
     * Resolve pixelate amount.
30
     * @return string The resolved pixelate amount.
31
     */
32
    public function getPixelate()
33
    {
34
        if (!is_numeric($this->pixel)) {
35
            return;
36
        }
37
38
        if ($this->pixel < 0 or $this->pixel > 1000) {
39
            return;
40
        }
41
42
        return (int) $this->pixel;
43
    }
44
}
45