This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace NwLaravel\FileStorage; |
||
4 | |||
5 | use Imagick; |
||
6 | use ImagickPixel; |
||
7 | |||
8 | class ImagineImagick implements Imagine |
||
9 | { |
||
10 | /** |
||
11 | * @var Imagick |
||
12 | */ |
||
13 | protected $image; |
||
14 | |||
15 | /** |
||
16 | * Construct |
||
17 | * |
||
18 | * @param string|blob $data |
||
19 | */ |
||
20 | public function __construct($data) |
||
21 | { |
||
22 | if ($this->isBinary($data)) { |
||
23 | $pathTmp = tempnam(sys_get_temp_dir(), 'img'); |
||
24 | file_put_contents($pathTmp, $data); |
||
25 | $this->image = new Imagick($pathTmp); |
||
26 | @unlink($pathTmp); |
||
0 ignored issues
–
show
|
|||
27 | } else { |
||
28 | $this->image = new Imagick($data); |
||
29 | } |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Determines if current source data is binary data |
||
34 | * |
||
35 | * @return boolean |
||
36 | */ |
||
37 | protected function isBinary($data) |
||
38 | { |
||
39 | if (is_string($data)) { |
||
40 | $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data); |
||
41 | return (substr($mime, 0, 4) != 'text' && $mime != 'application/x-empty'); |
||
42 | } |
||
43 | |||
44 | return false; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Execute in Canvas |
||
49 | * |
||
50 | * @param \Closure $callback |
||
51 | * |
||
52 | * @return Imagine |
||
53 | */ |
||
54 | protected function execute($callback) |
||
55 | { |
||
56 | $format = strtolower($this->image->getImageFormat()); |
||
57 | |||
58 | if ($format == 'gif') { |
||
59 | $this->image = $this->image->coalesceImages(); |
||
60 | do { |
||
61 | $callback($this->image); |
||
62 | } while ($this->image->nextImage()); |
||
63 | |||
64 | $this->image = $this->image->deconstructImages(); |
||
65 | } else { |
||
66 | $callback($this->image); |
||
67 | } |
||
68 | |||
69 | return $this; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Filesize |
||
74 | * |
||
75 | * @return int |
||
76 | */ |
||
77 | public function filesize() |
||
78 | { |
||
79 | return $this->image->getImageLength(); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Define Resize |
||
84 | * |
||
85 | * @param int $maxWidth |
||
86 | * @param int $maxHeight |
||
87 | * @param boolean $force |
||
88 | * |
||
89 | * @return Imagine |
||
90 | */ |
||
91 | public function resize($maxWidth, $maxHeight, $force = false) |
||
92 | { |
||
93 | return $this->execute(function ($image) use ($maxWidth, $maxHeight, $force) { |
||
94 | $width = $maxWidth; |
||
95 | $height = $maxHeight; |
||
96 | $imageWidth = $image->getImageWidth(); |
||
97 | $imageHeight = $image->getImageHeight(); |
||
98 | |||
99 | if(($maxWidth && $imageWidth > $maxWidth) || !$maxHeight) { |
||
100 | $height = floor(($imageHeight/$imageWidth)*$maxWidth); |
||
101 | if (!$height) { |
||
102 | $height = $imageHeight; |
||
103 | } |
||
104 | |||
105 | } else if(($maxHeight && $imageHeight > $maxHeight) || !$maxWidth) { |
||
106 | $width = floor(($imageWidth/$imageHeight)*$maxHeight); |
||
107 | if (!$width) { |
||
108 | $width = $imageWidth; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | $image->scaleImage($width, $height, !$force); |
||
113 | }); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Opacity |
||
118 | * |
||
119 | * @return Imagine |
||
120 | */ |
||
121 | public function opacity($opacity) |
||
122 | { |
||
123 | $opacity = intval($opacity); |
||
124 | |||
125 | if ($opacity > 0 && $opacity < 100) { |
||
126 | $this->execute(function ($image) use ($opacity) { |
||
127 | $image->setImageOpacity($opacity/100); |
||
128 | }); |
||
129 | } |
||
130 | |||
131 | return $this; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Watermark |
||
136 | * |
||
137 | * @param string $watermark |
||
138 | * @param string $position |
||
139 | * @param integer $opacity |
||
140 | * |
||
141 | * @return Imagine |
||
142 | */ |
||
143 | public function watermark($watermark, $position = 'center', $opacity = null) |
||
144 | { |
||
145 | if ($this->isImage($watermark)) { |
||
146 | $watermark = new Imagick($watermark); |
||
147 | } |
||
148 | |||
149 | if ($watermark instanceof Imagick) { |
||
150 | $opacity = intval($opacity); |
||
151 | if ($opacity > 0 && $opacity < 100) { |
||
152 | $watermark->setImageOpacity($opacity/100); |
||
153 | } |
||
154 | |||
155 | $self = $this; |
||
156 | |||
157 | $this->execute(function ($image) use ($watermark, $position, $self) { |
||
158 | $self->watermarkCanvas($image, $watermark, $position); |
||
159 | }); |
||
160 | } |
||
161 | |||
162 | return $this; |
||
163 | } |
||
164 | |||
165 | protected function watermarkCanvas(Imagick $image, Imagick $watermark, $position = 'center') |
||
166 | { |
||
167 | // how big are the images? |
||
168 | $iWidth = $image->getImageWidth(); |
||
169 | $iHeight = $image->getImageHeight(); |
||
170 | $wWidth = $watermark->getImageWidth(); |
||
171 | $wHeight = $watermark->getImageHeight(); |
||
172 | |||
173 | if ($iHeight < $wHeight || $iWidth < $wWidth) { |
||
174 | // resize the watermark |
||
175 | $watermark->scaleImage($iWidth, $iHeight, true); |
||
176 | |||
177 | // get new size |
||
178 | $wWidth = $watermark->getImageWidth(); |
||
179 | $wHeight = $watermark->getImageHeight(); |
||
180 | } |
||
181 | |||
182 | $xOffset = 0; |
||
0 ignored issues
–
show
$xOffset is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
183 | $yOffset = 0; |
||
0 ignored issues
–
show
$yOffset is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
184 | |||
185 | switch ($position) { |
||
186 | case 'center': |
||
187 | default: |
||
188 | $x = ($iWidth - $wWidth) / 2; |
||
189 | $y = ($iHeight - $wHeight) / 2; |
||
190 | break; |
||
191 | case 'topLeft': |
||
0 ignored issues
–
show
case 'topLeft': $x =... = $yOffset; break; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last
Loading history...
|
|||
192 | $x = $xOffset; |
||
193 | $y = $yOffset; |
||
194 | break; |
||
195 | case 'top': |
||
196 | case 'topCenter': |
||
197 | $x = ($iWidth - $wWidth) / 2; |
||
198 | $y = $yOffset; |
||
199 | break; |
||
200 | case 'topRight': |
||
201 | $x = $iWidth - $wWidth - $xOffset; |
||
202 | $y = $yOffset; |
||
203 | break; |
||
204 | case 'right': |
||
205 | case 'rightCenter': |
||
206 | $x = $iWidth - $wWidth - $xOffset; |
||
207 | $y = ($iHeight - $wHeight) / 2; |
||
208 | break; |
||
209 | case 'bottomRight': |
||
210 | $x = $iWidth - $wWidth - $xOffset; |
||
211 | $y = $iHeight - $wHeight - $yOffset; |
||
212 | break; |
||
213 | case 'bottom': |
||
214 | case 'bottomCenter': |
||
215 | $x = ($iWidth - $wWidth) / 2; |
||
216 | $y = $iHeight - $wHeight - $yOffset; |
||
217 | break; |
||
218 | case 'bottomLeft': |
||
219 | $x = $xOffset; |
||
220 | $y = $iHeight - $wHeight - $yOffset; |
||
221 | break; |
||
222 | case 'left': |
||
223 | case 'leftCenter': |
||
224 | $x = $xOffset; |
||
225 | $y = ($iHeight - $wHeight) / 2; |
||
226 | break; |
||
227 | } |
||
228 | |||
229 | $image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Is Image |
||
234 | * |
||
235 | * @param string $path |
||
236 | * |
||
237 | * @return boolean |
||
238 | */ |
||
239 | protected function isImage($path) |
||
240 | { |
||
241 | return (bool) ($path && is_file($path) && strpos(mime_content_type($path), 'image/')===0); |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * Crop |
||
246 | * |
||
247 | * @param integer $width |
||
248 | * @param integer $height |
||
249 | * @param integer $x |
||
250 | * @param integer $y |
||
251 | * |
||
252 | * @return binary |
||
253 | */ |
||
254 | public function crop($width, $height, $x, $y) |
||
255 | { |
||
256 | return $this->execute(function ($image) use ($width, $height, $x, $y) { |
||
0 ignored issues
–
show
The return type of
return $this->execute(fu..., $height, $x, $y); }); (NwLaravel\FileStorage\Imagine ) is incompatible with the return type declared by the interface NwLaravel\FileStorage\Imagine::crop of type NwLaravel\FileStorage\binary .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
257 | $image->cropImage($width, $height, $x, $y); |
||
258 | }); |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Rotate Image |
||
263 | * |
||
264 | * @param integer $angle |
||
265 | * |
||
266 | * @return binary |
||
267 | */ |
||
268 | public function rotate($angle) |
||
269 | { |
||
270 | $angle = intval($angle); |
||
271 | |||
272 | if ($angle > -360 && $angle < 360) { |
||
273 | $this->execute(function ($image) use ($angle) { |
||
274 | $image->rotateImage('#ffffff', $angle); |
||
275 | }); |
||
276 | } |
||
277 | |||
278 | return $this; |
||
0 ignored issues
–
show
The return type of
return $this; (NwLaravel\FileStorage\ImagineImagick ) is incompatible with the return type declared by the interface NwLaravel\FileStorage\Imagine::rotate of type NwLaravel\FileStorage\binary .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
279 | } |
||
280 | |||
281 | /** |
||
282 | * Strip Profiles |
||
283 | * |
||
284 | * @param string $except |
||
0 ignored issues
–
show
There is no parameter named
$except . 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 /**
* @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...
|
|||
285 | * |
||
286 | * @return this |
||
287 | */ |
||
288 | public function stripProfiles() |
||
289 | { |
||
290 | $profiles = $this->image->getImageProfiles('icc', true); |
||
291 | |||
292 | $this->image->stripImage(); |
||
293 | |||
294 | if(!empty($profiles)) |
||
295 | $this->image->profileImage('icc', $profiles['icc']); |
||
296 | |||
297 | return $this; |
||
0 ignored issues
–
show
The return type of
return $this; (NwLaravel\FileStorage\ImagineImagick ) is incompatible with the return type declared by the interface NwLaravel\FileStorage\Imagine::stripProfiles of type NwLaravel\FileStorage\this .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Encode |
||
302 | * |
||
303 | * @param string $format |
||
304 | * @param integer $quality |
||
305 | * |
||
306 | * @return binary |
||
307 | */ |
||
308 | public function encode($format = null, $quality = null) |
||
309 | { |
||
310 | return $this->image->getImagesBlob(); |
||
0 ignored issues
–
show
The return type of
return $this->image->getImagesBlob(); (string ) is incompatible with the return type declared by the interface NwLaravel\FileStorage\Imagine::encode of type NwLaravel\FileStorage\binary .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
311 | } |
||
312 | |||
313 | /** |
||
314 | * Save |
||
315 | * |
||
316 | * @param string $path |
||
317 | * @param integer $quality |
||
318 | * |
||
319 | * @return binary |
||
320 | */ |
||
321 | public function save($path, $quality = null) |
||
322 | { |
||
323 | $quality = intval($quality); |
||
324 | if ($quality > 0 && $quality <= 100) { |
||
325 | $this->image->setImageCompressionQuality($quality); |
||
326 | } |
||
327 | $this->image->writeImage($path); |
||
328 | |||
329 | return $this; |
||
0 ignored issues
–
show
The return type of
return $this; (NwLaravel\FileStorage\ImagineImagick ) is incompatible with the return type declared by the interface NwLaravel\FileStorage\Imagine::save of type NwLaravel\FileStorage\binary .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
330 | } |
||
331 | } |
||
332 |
If you suppress an error, we recommend checking for the error condition explicitly: