Completed
Push — master ( 1c65b0...3a1fce )
by Stanislav
20s queued 17s
created

file::watermark_image()   D

Complexity

Conditions 17
Paths 149

Size

Total Lines 78
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 306

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 47
c 2
b 1
f 0
dl 0
loc 78
ccs 0
cts 46
cp 0
rs 4.8083
cc 17
nc 149
nop 4
crap 306

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
*
5
* @package phpBB Gallery Core
6
* @copyright (c) 2014 nickvergessen
7
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
*
9
*/
10
11
namespace phpbbgallery\core\file;
12
13
/**
14
 * A little class for all the actions that the gallery does on images.
15
*
16
* resize, rotate, watermark, crete thumbnail, write to hdd, send to browser
17
 *
18
 * @property \phpbbgallery\core\url url
19
 * @property \phpbb\request\request request
20
 */
21
class file
22
{
23
	const THUMBNAIL_INFO_HEIGHT = 16;
24
	const GDLIB1 = 1;
25
	const GDLIB2 = 2;
26
27
	public $chmod = 0644;
28
29
	public $errors = array();
30
	private $browser_cache = true;
31
	private $last_modified = 0;
32
33
	public $gd_version = 0;
34
35
	public $image;
36
	public $image_content_type;
37
	public $image_name = '';
38
	public $image_quality = 100;
39
	public $image_size = array();
40
	public $image_source = '';
41
	public $image_type;
42
43
	public $max_file_size = 0;
44
	public $max_height = 0;
45
	public $max_width = 0;
46
47
	public $resized = false;
48
	public $rotated = false;
49
50
	public $thumb_height = 0;
51
	public $thumb_width = 0;
52
53
	public $watermark;
54
	public $watermark_size = array();
55
	public $watermark_source = '';
56
	public $watermarked = false;
57
58
	/**
59
	 * Constructor - init some basic stuff
60
	 *
61
	 * @param \phpbb\request\request $request
62
	 * @param \phpbbgallery\core\url $url
63
	 * @param \phpbbgallery\core\config $gallery_config
64
	 * @param int $gd_version
65
	 */
66 96
	public function __construct(\phpbb\request\request $request, \phpbbgallery\core\url $url, \phpbbgallery\core\config $gallery_config, $gd_version)
0 ignored issues
show
Bug introduced by
The type phpbb\request\request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
	{
68 96
		$this->request = $request;
69 96
		$this->url = $url;
70 96
		$this->gallery_config = $gallery_config;
0 ignored issues
show
Bug Best Practice introduced by
The property gallery_config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
71 96
		$this->gd_version = $gd_version;
72 96
	}
73
74
	public function set_image_options($max_file_size, $max_height, $max_width)
75
	{
76
		$this->max_file_size = $max_file_size;
77
		$this->max_height = $max_height;
78
		$this->max_width = $max_width;
79
	}
80
81
	public function set_image_data($source = '', $name = '', $size = 0, $force_empty_image = false)
82
	{
83
		if ($source)
84
		{
85
			$this->image_source = $source;
86
		}
87
		if ($name)
88
		{
89
			$this->image_name = $name;
90
		}
91
		if ($size)
92
		{
93
			$this->image_size['file'] = $size;
94
		}
95
		if ($force_empty_image)
96
		{
97
			$this->image = null;
98
			$this->watermarked = false;
99
			$this->rotated = false;
100
			$this->resized = false;
101
		}
102
	}
103
104
	/**
105
	 * Get image mimetype by filename
106
	 *
107
	 * Only use this, if the image is secure. As we created all these images, they should be...
108
	 * @param $filename
109
	 * @return string
110
	 */
111
	static public function mimetype_by_filename($filename)
112
	{
113
		switch (utf8_substr(strtolower($filename), -4))
0 ignored issues
show
Bug introduced by
The function utf8_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
		switch (/** @scrutinizer ignore-call */ utf8_substr(strtolower($filename), -4))
Loading history...
114
		{
115
			case '.png':
116
				return 'image/png';
117
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
118
			case '.gif':
119
				return 'image/gif';
120
			break;
121
			case 'jpeg':
122
			case '.jpg':
123
				return 'image/jpeg';
124
			break;
125
			case '.webp':
126
				return 'image/webp';
127
			break;
128
		}
129
130
		return '';
131
	}
132
133
	/**
134
	 * Read image
135
	 * @param bool $force_filesize
136
	 * @return bool
137
	 */
138
	public function read_image($force_filesize = false)
139
	{
140
		if (!file_exists($this->image_source))
141
		{
142
			return false;
143
		}
144
145
		switch (utf8_substr(strtolower($this->image_source), -4))
0 ignored issues
show
Bug introduced by
The function utf8_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

145
		switch (/** @scrutinizer ignore-call */ utf8_substr(strtolower($this->image_source), -4))
Loading history...
146
		{
147
			case '.png':
148
				$this->image = imagecreatefrompng($this->image_source);
149
				imagealphablending($this->image, true); // Set alpha blending on ...
150
				imagesavealpha($this->image, true); // ... and save alphablending!
151
				$this->image_type = 'png';
152
			break;
153
			case '.webp':
154
				$this->image = imagecreatefromwebp($this->image_source);
155
				$this->image_type = 'webp';
156
			break;
157
			case '.gif':
158
				$this->image = imagecreatefromgif($this->image_source);
159
				$this->image_type = 'gif';
160
			break;
161
			default:
162
				$this->image = imagecreatefromjpeg($this->image_source);
163
				$this->image_type = 'jpeg';
164
			break;
165
		}
166
167
		$file_size = 0;
168
		if (isset($this->image_size['file']))
169
		{
170
			$file_size = $this->image_size['file'];
171
		}
172
		else if ($force_filesize)
173
		{
174
			$file_size = @filesize($this->image_source);
175
		}
176
177
		$image_size = getimagesize($this->image_source);
178
179
		$this->image_size['file'] = $file_size;
180
		$this->image_size['width'] = $image_size[0];
181
		$this->image_size['height'] = $image_size[1];
182
183
		$this->image_content_type = $image_size['mime'];
184
	}
185
186
	/**
187
	 * Write image to disk
188
	 * @param $destination
189
	 * @param int $quality
190
	 * @param bool $destroy_image
191
	 */
192
	public function write_image($destination, $quality = -1, $destroy_image = false)
193
	{
194
		if ($quality == -1)
195
		{
196
			$quality = $this->gallery_config->get('jpg_quality');
197
		}
198
		switch ($this->image_type)
199
		{
200
			case 'jpeg':
201
				imagejpeg($this->image, $destination, $quality);
202
			break;
203
			case 'png':
204
				imagepng($this->image, $destination);
205
			break;
206
			case 'webp':
207
				imagewebp($this->image, $destination);
208
			break;
209
			case 'gif':
210
				imagegif($this->image, $destination);
211
			break;
212
		}
213
		@chmod($destination, $this->chmod);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for chmod(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

213
		/** @scrutinizer ignore-unhandled */ @chmod($destination, $this->chmod);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
214
215
		if ($destroy_image)
216
		{
217
			imagedestroy($this->image);
218
		}
219
	}
220
221
	/**
222
	 * Get a browser friendly UTF-8 encoded filename
223
	 *
224
	 * @param $file
225
	 * @return string
226
	 */
227
	public function header_filename($file)
228
	{
229
		$raw = $this->request->server('HTTP_USER_AGENT');
230
		$user_agent = htmlspecialchars($raw);
231
232
		// There be dragons here.
233
		// Not many follows the RFC...
234
		if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Safari') !== false || strpos($user_agent, 'Konqueror') !== false)
235
		{
236
			return "filename=" . rawurlencode($file);
237
		}
238
239
		// follow the RFC for extended filename for the rest
240
		return "filename*=UTF-8''" . rawurlencode($file);
241
	}
242
243
	/**
244
	* We need to disable the "last-modified" caching for guests and in cases of image-errors,
245
	* so that they can view them, if they logged in or the error was fixed.
246
	*/
247
	public function disable_browser_cache()
248
	{
249
		$this->browser_cache = false;
250
	}
251
252
	/**
253
	 * Collect the last timestamp where something changed.
254
	 * This must contain:
255
	 *    - Last change of the file
256
	 *    - Last change of user's permissions
257
	 *    - Last change of user's groups
258
	 *    - Last change of watermark config
259
	 *    - Last change of watermark file
260
	 * @param $timestamp
261
	 */
262
	public function set_last_modified($timestamp)
263
	{
264
		$this->last_modified = max($timestamp, $this->last_modified);
265
	}
266
267
	static public function is_ie_greater7($browser)
268
	{
269
		return (bool) preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser));
270
	}
271
272
	public function create_thumbnail($max_width, $max_height, $print_details = false, $additional_height = 0, $image_size = array())
273
	{
274
		$this->resize_image($max_width, $max_height, (($print_details) ? $additional_height : 0));
275
276
		// Create image details credits to Dr.Death
277
		if ($print_details && sizeof($image_size))
278
		{
279
			$dimension_font = 1;
280
			$dimension_string = $image_size['width'] . "x" . $image_size['height'] . "(" . intval($image_size['file'] / 1024) . "KiB)";
281
			$dimension_colour = imagecolorallocate($this->image, 255, 255, 255);
282
			$dimension_height = imagefontheight($dimension_font);
283
			$dimension_width = imagefontwidth($dimension_font) * strlen($dimension_string);
284
			$dimension_x = ($this->image_size['width'] - $dimension_width) / 2;
285
			$dimension_y = $this->image_size['height'] + (($additional_height - $dimension_height) / 2);
286
			$black_background = imagecolorallocate($this->image, 0, 0, 0);
287
			imagefilledrectangle($this->image, 0, $this->thumb_height, $this->thumb_width, $this->thumb_height + $additional_height, $black_background);
288
			imagestring($this->image, 1, $dimension_x, $dimension_y, $dimension_string, $dimension_colour);
289
		}
290
	}
291
292
	public function resize_image($max_width, $max_height, $additional_height = 0)
293
	{
294
		if (!$this->image)
295
		{
296
			$this->read_image();
297
		}
298
299
		if (($this->image_size['height'] <= $max_height) && ($this->image_size['width'] <= $max_width))
300
		{
301
			// image is small enough, nothing to do here.
302
			return;
303
		}
304
305
		if (($this->image_size['height'] / $max_height) > ($this->image_size['width'] / $max_width))
306
		{
307
			$this->thumb_height	= $max_height;
308
			$this->thumb_width	= round($max_width * (($this->image_size['width'] / $max_width) / ($this->image_size['height'] / $max_height)));
309
		}
310
		else
311
		{
312
			$this->thumb_height	= round($max_height * (($this->image_size['height'] / $max_height) / ($this->image_size['width'] / $max_width)));
313
			$this->thumb_width	= $max_width;
314
		}
315
316
		$image_copy = (($this->gd_version == self::GDLIB1) ? @imagecreate($this->thumb_width, $this->thumb_height + $additional_height) : @imagecreatetruecolor($this->thumb_width, $this->thumb_height + $additional_height));
317
		if ($this->image_type != 'jpeg')
318
		{
319
			imagealphablending($image_copy, false);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagealphablending() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

319
			imagealphablending(/** @scrutinizer ignore-type */ $image_copy, false);
Loading history...
320
			imagesavealpha($image_copy, true);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagesavealpha() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

320
			imagesavealpha(/** @scrutinizer ignore-type */ $image_copy, true);
Loading history...
321
			$transparent = imagecolorallocatealpha($image_copy, 255, 255, 255, 127);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagecolorallocatealpha() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

321
			$transparent = imagecolorallocatealpha(/** @scrutinizer ignore-type */ $image_copy, 255, 255, 255, 127);
Loading history...
322
			imagefilledrectangle($image_copy, 0, 0, $this->thumb_width, $this->thumb_height + $additional_height, $transparent);
0 ignored issues
show
Bug introduced by
It seems like $image_copy can also be of type false; however, parameter $image of imagefilledrectangle() does only seem to accept GdImage|resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

322
			imagefilledrectangle(/** @scrutinizer ignore-type */ $image_copy, 0, 0, $this->thumb_width, $this->thumb_height + $additional_height, $transparent);
Loading history...
323
		}
324
325
		$resize_function = ($this->gd_version == self::GDLIB1) ? 'imagecopyresized' : 'imagecopyresampled';
326
		$resize_function($image_copy, $this->image, 0, 0, 0, 0, $this->thumb_width, $this->thumb_height, $this->image_size['width'], $this->image_size['height']);
327
328
		imagealphablending($image_copy, true);
329
		imagesavealpha($image_copy, true);
330
		$this->image = $image_copy;
331
332
		$this->image_size['height'] = $this->thumb_height;
333
		$this->image_size['width'] = $this->thumb_width;
334
335
		$this->resized = true;
336
	}
337
338
	/**
339
	 * Rotate the image
340
	 * Usage optimized for 0�, 90�, 180� and 270� because of the height and width
341
	 *
342
	 * @param $angle
343
	 * @param $ignore_dimensions
344
	 */
345
	public function rotate_image($angle, $ignore_dimensions)
346
	{
347
		if (!function_exists('imagerotate'))
348
		{
349
			$this->errors[] = array('ROTATE_IMAGE_FUNCTION', $angle);
350
			return;
351
		}
352
		if (($angle <= 0) || (($angle % 90) != 0))
353
		{
354
			$this->errors[] = array('ROTATE_IMAGE_ANGLE', $angle);
355
			return;
356
		}
357
358
		if (!$this->image)
359
		{
360
			$this->read_image();
361
		}
362
		if ((($angle / 90) % 2) == 1)
363
		{
364
			// Left or Right, we need to switch the height and width
365
			if (!$ignore_dimensions && (($this->image_size['height'] > $this->max_width) || ($this->image_size['width'] > $this->max_height)))
366
			{
367
				// image would be to wide/high
368
				if ($this->image_size['height'] > $this->max_width)
369
				{
370
					$this->errors[] = array('ROTATE_IMAGE_WIDTH');
371
				}
372
				if ($this->image_size['width'] > $this->max_height)
373
				{
374
					$this->errors[] = array('ROTATE_IMAGE_HEIGHT');
375
				}
376
				return;
377
			}
378
			$new_width = $this->image_size['height'];
379
			$this->image_size['height'] = $this->image_size['width'];
380
			$this->image_size['width'] = $new_width;
381
		}
382
		$this->image = imagerotate($this->image, $angle, 0);
383
384
		$this->rotated = true;
385
	}
386
387
	/**
388
	 * Watermark the image:
389
	 *
390
	 * @param $watermark_source
391
	 * @param int $watermark_position summary of the parameters for vertical and horizontal adjustment
392
	 * @param int $min_height
393
	 * @param int $min_width
394
	 */
395
	public function watermark_image($watermark_source, $watermark_position = 20, $min_height = 0, $min_width = 0)
396
	{
397
		$this->watermark_source = $watermark_source;
398
		if (!$this->watermark_source || !file_exists($this->watermark_source))
399
		{
400
			$this->errors[] = array('WATERMARK_IMAGE_SOURCE');
401
			return;
402
		}
403
404
		if (!$this->image)
405
		{
406
			$this->read_image();
407
		}
408
409
		if (($min_height && ($this->image_size['height'] < $min_height)) || ($min_width && ($this->image_size['width'] < $min_width)))
410
		{
411
			return;
412
			//$this->errors[] = array('WATERMARK_IMAGE_DIMENSION');
413
		}
414
		$get_dot = strrpos($this->image_source, '.');
415
		$get_wm_name = substr_replace($this->image_source, '_wm', $get_dot, 0);
416
		if (file_exists($get_wm_name))
0 ignored issues
show
Bug introduced by
It seems like $get_wm_name can also be of type array; however, parameter $filename of file_exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

416
		if (file_exists(/** @scrutinizer ignore-type */ $get_wm_name))
Loading history...
417
		{
418
			$this->image_source = $get_wm_name;
419
			$this->read_image();
420
		}
421
		else
422
		{
423
			$this->watermark_size = getimagesize($this->watermark_source);
424
			switch ($this->watermark_size['mime'])
425
			{
426
				case 'image/png':
427
					$imagecreate = 'imagecreatefrompng';
428
					break;
429
				case 'image/webp':
430
					$imagecreate = 'imagecreatefromwebp';
431
					break;
432
				case 'image/gif':
433
					$imagecreate = 'imagecreatefromgif';
434
					break;
435
				default:
436
					$imagecreate = 'imagecreatefromjpeg';
437
					break;
438
			}
439
440
			// Get the watermark as resource.
441
			if (($this->watermark = $imagecreate($this->watermark_source)) === false)
442
			{
443
				$this->errors[] = array('WATERMARK_IMAGE_IMAGECREATE');
444
			}
445
446
			$phpbb_gallery_constants = new \phpbbgallery\core\constants();
447
			// Where do we display the watermark? up-left, down-right, ...?
448
			$dst_x = (($this->image_size['width'] * 0.5) - ($this->watermark_size[0] * 0.5));
449
			$dst_y = ($this->image_size['height'] - $this->watermark_size[1] - 5);
450
			if ($watermark_position & $phpbb_gallery_constants::WATERMARK_LEFT)
451
			{
452
				$dst_x = 5;
453
			}
454
			else if ($watermark_position & $phpbb_gallery_constants::WATERMARK_RIGHT)
455
			{
456
				$dst_x = ($this->image_size['width'] - $this->watermark_size[0] - 5);
457
			}
458
			if ($watermark_position & $phpbb_gallery_constants::WATERMARK_TOP)
459
			{
460
				$dst_y = 5;
461
			}
462
			else if ($watermark_position & $phpbb_gallery_constants::WATERMARK_MIDDLE)
463
			{
464
				$dst_y = (($this->image_size['height'] * 0.5) - ($this->watermark_size[1] * 0.5));
465
			}
466
			imagecopy($this->image, $this->watermark, $dst_x, $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]);
0 ignored issues
show
Bug introduced by
It seems like $dst_y can also be of type double; however, parameter $dst_y of imagecopy() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

466
			imagecopy($this->image, $this->watermark, $dst_x, /** @scrutinizer ignore-type */ $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]);
Loading history...
Bug introduced by
It seems like $dst_x can also be of type double; however, parameter $dst_x of imagecopy() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

466
			imagecopy($this->image, $this->watermark, /** @scrutinizer ignore-type */ $dst_x, $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]);
Loading history...
467
			imagedestroy($this->watermark);
468
			$this->write_image($get_wm_name);
469
			$this->image_source = $get_wm_name;
470
			$this->read_image();
471
		}
472
		$this->watermarked = true;
473
	}
474
475
	/**
476
	* Delete file from disc.
477
	*
478
	* @param	mixed		$files		String with filename or an array of filenames
479
	*									Array-Format: $image_id => $filename
480
	* @param	array		$locations	Array of valid url::path()s where the image should be deleted from
481
	*/
482
	public function delete($files, $locations = array('thumbnail', 'medium', 'upload'))
483
	{
484
		if (!is_array($files))
485
		{
486
			$files = array(1 => $files);
487
		}
488
		// Let's delete watermarked
489
		$this->delete_wm($files);
490
		foreach ($files as $image_id => $file)
491
		{
492
			foreach ($locations as $location)
493
			{
494
				@unlink($this->url->path($location) . $file);
0 ignored issues
show
Bug introduced by
Are you sure $this->url->path($location) of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

494
				@unlink(/** @scrutinizer ignore-type */ $this->url->path($location) . $file);
Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

494
				/** @scrutinizer ignore-unhandled */ @unlink($this->url->path($location) . $file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
495
			}
496
		}
497
	}
498
499
	/**
500
	 * @param $files
501
	 * @param array $locations
502
	 */
503
	public function delete_cache($files, $locations = array('thumbnail', 'medium'))
504
	{
505
		if (!is_array($files))
506
		{
507
			$files = array(1 => $files);
508
		}
509
		$this->delete_wm($files);
510
		foreach ($files as $image_id => $file)
511
		{
512
			foreach ($locations as $location)
513
			{
514
				@unlink($this->url->path($location) . $file);
0 ignored issues
show
Bug introduced by
Are you sure $this->url->path($location) of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

514
				@unlink(/** @scrutinizer ignore-type */ $this->url->path($location) . $file);
Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

514
				/** @scrutinizer ignore-unhandled */ @unlink($this->url->path($location) . $file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
515
			}
516
		}
517
	}
518
519
	/**
520
	 * @param $files
521
	 */
522
	public function delete_wm($files)
523
	{
524
		$locations = array('upload', 'medium');
525
		if (!is_array($files))
526
		{
527
			$files = array(1 => $files);
528
		}
529
		foreach ($files as $image_id => $file)
530
		{
531
			$get_dot = strrpos($file, '.');
532
			$get_wm_name = substr_replace($file, '_wm', $get_dot, 0);
533
			foreach ($locations as $location)
534
			{
535
				@unlink($this->url->path($location) . $get_wm_name);
0 ignored issues
show
Bug introduced by
Are you sure $this->url->path($location) of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

535
				@unlink(/** @scrutinizer ignore-type */ $this->url->path($location) . $get_wm_name);
Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

535
				/** @scrutinizer ignore-unhandled */ @unlink($this->url->path($location) . $get_wm_name);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
536
			}
537
		}
538
	}
539
}
540