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 |
|
|
|
|
39
|
|
|
* @param integer $width |
40
|
|
|
* @param integer $height |
41
|
|
|
* @param mixed $content |
42
|
|
|
*/ |
43
|
1 |
|
function __construct($width, $height, $content = null) { |
|
|
|
|
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
|
|
|
|
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 methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.