Dimension   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 70.59%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 45
ccs 12
cts 17
cp 0.7059
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B get() 0 14 5
1
<?php
2
3
namespace League\Glide\Manipulators\Helpers;
4
5
use Intervention\Image\Image;
6
7
class Dimension
8
{
9
    /**
10
     * The source image.
11
     * @var Image
12
     */
13
    protected $image;
14
15
    /**
16
     * The device pixel ratio.
17
     * @var integer
18
     */
19
    protected $dpr;
20
21
    /**
22
     * Create dimension helper instance.
23
     * @param Image   $image The source image.
24
     * @param integer $dpr   The device pixel ratio.
25
     */
26 26
    public function __construct(Image $image, $dpr = 1)
27
    {
28 26
        $this->image = $image;
29 26
        $this->dpr = $dpr;
30 26
    }
31
32
    /**
33
     * Resolve the dimension.
34
     * @param  string $value The dimension value.
35
     * @return double The resolved dimension.
36
     */
37 26
    public function get($value)
38
    {
39 26
        if (is_numeric($value) and $value > 0) {
40 18
            return (double) $value * $this->dpr;
41
        }
42
43 10
        if (preg_match('/^(\d{1,2}(?!\d)|100)(w|h)$/', $value, $matches)) {
44 6
            if ($matches[2] === 'h') {
45 4
                return (double) $this->image->height() * ($matches[1] / 100);
46
            }
47
48 4
            return (double) $this->image->width() * ($matches[1] / 100);
49
        }
50 6
    }
51
}
52