Completed
Push — master ( e60207...37fe77 )
by Jonathan
05:38
created

Contrast::getContrast()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

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