Item   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 0
dl 0
loc 164
ccs 39
cts 39
cp 1
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getWidth() 0 4 1
A getHeight() 0 4 1
A getWidthPercent() 0 4 1
A getHeightPercent() 0 4 1
A setWidth() 0 5 1
A setHeight() 0 5 1
A getScale() 0 4 1
A getOriginalWidth() 0 4 1
A getOriginalHeight() 0 4 1
A getAspect() 0 4 1
A isLandscape() 0 4 1
A isPortrait() 0 4 1
A isSquare() 0 4 1
A getContent() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace CL\FluidGallery;
4
5
/**
6
 * @author    Ivan Kerin <[email protected]>
7
 * @copyright 2015, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
class Item
11
{
12
    /**
13
     * @var integer
14
     */
15
    private $originalWidth;
16
17
    /**
18
     * @var integer
19
     */
20
    private $originalHeight;
21
22
    /**
23
     * @var float|integer
24
     */
25
    private $width;
26
27
    /**
28
     * @var float|integer
29
     */
30
    private $height;
31
32
    /**
33
     * @var mixed
34
     */
35
    private $content;
36
37
    /**
38
     * @param string  $url
0 ignored issues
show
Bug introduced by
There is no parameter named $url. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
39
     * @param integer $width
40
     * @param integer $height
41
     * @param mixed   $content
42
     */
43 1
    function __construct($width, $height, $content = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
44 1
        $this->originalWidth = $this->width = (int) $width;
45 1
        $this->originalHeight = $this->height = (int) $height;
46 1
        $this->content = $content;
47 1
    }
48
49
    /**
50
     * @return float|integer
51
     */
52 3
    public function getWidth()
53
    {
54 3
        return $this->width;
55
    }
56
57
    /**
58
     * @return float|integer
59
     */
60 3
    public function getHeight()
61
    {
62 3
        return $this->height;
63
    }
64
65
    /**
66
     * @param float $total
67
     * @return float
68
     */
69 1
    public function getWidthPercent($total)
70
    {
71 1
        return ($this->width / $total) * 100;
72
    }
73
74
    /**
75
     * @param float $total
76
     * @return float
77
     */
78 1
    public function getHeightPercent($total)
79
    {
80 1
        return ($this->height / $total) * 100;
81
    }
82
83
    /**
84
     * set width, keeping aspect ratio
85
     *
86
     * @param integer $width
87
     */
88 1
    public function setWidth($width)
89
    {
90 1
        $this->width = $width;
91 1
        $this->height = $width / $this->getAspect();
92 1
    }
93
94
    /**
95
     * set height, keeping aspect ratio
96
     *
97
     * @param integer $height
98
     */
99 1
    public function setHeight($height)
100
    {
101 1
        $this->height = $height;
102 1
        $this->width = $height * $this->getAspect();
103 1
    }
104
105
    /**
106
     * @return float
107
     */
108 2
    public function getScale()
109
    {
110 2
        return $this->width/$this->originalWidth;
111
    }
112
113
    /**
114
     * @return integer
115
     */
116 3
    public function getOriginalWidth()
117
    {
118 3
        return $this->originalWidth;
119
    }
120
121
    /**
122
     * @return integer
123
     */
124 3
    public function getOriginalHeight()
125
    {
126 3
        return $this->originalHeight;
127
    }
128
129
    /**
130
     * @return float
131
     */
132 1
    public function getAspect()
133
    {
134 1
        return $this->originalWidth / $this->originalHeight;
135
    }
136
137
    /**
138
     * @return boolean
139
     */
140 3
    public function isLandscape()
141
    {
142 3
        return $this->getAspect() > 1;
143
    }
144
145
    /**
146
     * @return boolean
147
     */
148 3
    public function isPortrait()
149
    {
150 3
        return $this->getAspect() < 1;
151
    }
152
153
    /**
154
     * @return boolean
155
     */
156 3
    public function isSquare()
157
    {
158 3
        return $this->getAspect() == 1;
159
    }
160
161
    /**
162
     * @return string
163
     */
164 1
    public function getContent()
165
    {
166 1
        return $this->content;
167
    }
168
169 1
    public function __toString()
170
    {
171 1
        return "[Image {$this->originalWidth}x{$this->originalHeight} ({$this->content})]";
172
    }
173
}
174