Builder   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 119
ccs 27
cts 27
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A circle() 0 6 1
A fit() 0 10 2
A height() 0 6 1
A width() 0 6 1
A dpr() 0 6 1
A getManipulations() 0 8 2
A getKey() 0 4 1
1
<?php
2
3
namespace ArjanWestdorp\Imaginary;
4
5
class Builder
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $key;
11
    /**
12
     * @var array
13
     */
14
    protected $manipulations;
15
    /**
16
     * @var string
17
     */
18
    protected $url;
19
20
    /**
21
     * Builder constructor.
22
     *
23
     * @param string $key
24
     */
25 18
    public function __construct($key)
26
    {
27 18
        $this->key = $key;
28 18
    }
29
30
    /**
31
     * Make a circle of the image with the given radius.
32
     *
33
     * @param string $radius
34
     * @return $this
35
     */
36 2
    public function circle($radius = 'max')
37
    {
38 2
        $this->manipulations['r'] = $radius;
39
40 2
        return $this;
41
    }
42
43
    /**
44
     * Fit the image when resizing it.
45
     *
46
     * @param null|string $gravity
47
     * @return $this
48
     */
49 5
    public function fit($gravity = null)
50
    {
51 5
        $this->manipulations['c'] = 'fit';
52
53 5
        if (!is_null($gravity)) {
54 4
            $this->manipulations['g'] = $gravity;
55 4
        }
56
57 5
        return $this;
58
    }
59
60
    /**
61
     * Set the desired height of the image.
62
     *
63
     * @param int $height
64
     * @return $this
65
     */
66 3
    public function height($height)
67
    {
68 3
        $this->manipulations['h'] = $height;
69
70 3
        return $this;
71
    }
72
73
    /**
74
     * Set the desired width of the image.
75
     *
76
     * @param int $width
77
     * @return $this
78
     */
79 6
    public function width($width)
80
    {
81 6
        $this->manipulations['w'] = $width;
82
83 6
        return $this;
84
    }
85
86
    /**
87
     * Set the desired dpr of the image.
88
     *
89
     * @param mixed $dpr
90
     * @return $this
91
     */
92 3
    public function dpr($dpr = 'auto')
93
    {
94 3
        $this->manipulations['dpr'] = $dpr;
95
96 3
        return $this;
97
    }
98
99
    /**
100
     * Get the string representation of all manipulations that
101
     * need to be executed on the given resource.
102
     *
103
     * @return string|null
104
     */
105
    public function getManipulations()
106
    {
107 14
        $manipulations = array_map(function ($key) {
108 13
            return $key . '_' . $this->manipulations[$key];
109 14
        }, array_keys($this->manipulations ?: []));
110
111 14
        return implode(',', $manipulations);
112
    }
113
114
    /**
115
     * Get the key where we build the url for.
116
     *
117
     * @return string
118
     */
119 14
    public function getKey()
120
    {
121 14
        return $this->key;
122
    }
123
}