Gamma::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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