ApplyFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 6
1
<?php
2
	/**
3
##DOC-SIGNATURE##
4
5
    This file is part of WideImage.
6
		
7
    WideImage is free software; you can redistribute it and/or modify
8
    it under the terms of the GNU Lesser General Public License as published by
9
    the Free Software Foundation; either version 2.1 of the License, or
10
    (at your option) any later version.
11
		
12
    WideImage is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
16
		
17
    You should have received a copy of the GNU Lesser General Public License
18
    along with WideImage; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21
    * @package Internal/Operations
22
  **/
23
24
namespace WideImage\Operation;
25
26
use WideImage\Exception\GDFunctionResultException;
27
28
/**
29
 * ApplyFilter operation class
30
 * 
31
 * @package Internal/Operations
32
 */
33
class ApplyFilter
34
{
35
	/**
36
	 * A list of filters that only accept one arguments for imagefilter()
37
	 *
38
	 * @var array
39
	 */
40
	protected static $one_arg_filters = array(IMG_FILTER_SMOOTH, IMG_FILTER_CONTRAST, IMG_FILTER_BRIGHTNESS);
41
	
42
	/**
43
	 * Executes imagefilter
44
	 *
45
	 * @param \WideImage\Image $image
46
	 * @param int $filter 
47
	 * @param numeric $arg1
0 ignored issues
show
Bug introduced by
The type WideImage\Operation\numeric 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...
48
	 * @param numeric $arg2
49
	 * @param numeric $arg3
50
	 * @return \WideImage\TrueColorImage
51
	 */
52
	public function execute($image, $filter, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null)
53
	{
54
		$new = $image->asTrueColor();
55
		
56
		if (in_array($filter, static::$one_arg_filters)) {
57
			$res = imagefilter($new->getHandle(), $filter, $arg1);
0 ignored issues
show
Bug introduced by
It seems like $arg1 can also be of type WideImage\Operation\numeric; however, parameter $arg1 of imagefilter() 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

57
			$res = imagefilter($new->getHandle(), $filter, /** @scrutinizer ignore-type */ $arg1);
Loading history...
58
		} elseif (defined('IMG_FILTER_PIXELATE') && $filter == IMG_FILTER_PIXELATE) {
59
			$res = imagefilter($new->getHandle(), $filter, $arg1, $arg2);
0 ignored issues
show
Bug introduced by
It seems like $arg2 can also be of type WideImage\Operation\numeric; however, parameter $arg2 of imagefilter() 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

59
			$res = imagefilter($new->getHandle(), $filter, $arg1, /** @scrutinizer ignore-type */ $arg2);
Loading history...
60
		} elseif ($filter == IMG_FILTER_COLORIZE) {
61
			$res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, $arg3, $arg4);
0 ignored issues
show
Bug introduced by
It seems like $arg3 can also be of type WideImage\Operation\numeric; however, parameter $arg3 of imagefilter() 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

61
			$res = imagefilter($new->getHandle(), $filter, $arg1, $arg2, /** @scrutinizer ignore-type */ $arg3, $arg4);
Loading history...
62
		} else {
63
			$res = imagefilter($new->getHandle(), $filter);
64
		}
65
		
66
		if (!$res) {
67
			throw new GDFunctionResultException("imagefilter() returned false");
68
		}
69
		
70
		return $new;
71
	}
72
}
73