Completed
Push — master ( 72430f...dafba8 )
by Jonathan
04:56
created

Brightness::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0625

Importance

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