Passed
Push — master ( 3c6756...8b3b37 )
by Michael
14:24 queued 07:02
created

Demo_applyConvolution::execute()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 17
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 26
rs 9.3888
1
<?php
2
	/**
3
	 * @package Demos
4
	 */
5
	class Demo_applyConvolution extends Demo
6
	{
7
		public $order = 2025;
8
		
9
		protected $base_matrix = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
10
		
11
		function init()
12
		{
13
			$this->addField(new Field('matrix', '2 0 0, 0 -1 0, 0 0 -1', '3x3 float matrix; separate rows with a comma, and columns with a space'));
14
			$this->addField(new FloatField('div', 1));
15
			$this->addField(new FloatField('offset', 220));
16
		}
17
		
18
		function execute($image, $request)
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...
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

18
		function execute($image, /** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
		{
20
			$mstr = $this->fval('matrix');
21
			$rows = explode(',', $mstr);
22
			
23
			$matrix = array();
24
			foreach ($this->base_matrix as $idx => $base_row)
25
			{
26
				$build_row = array();
27
				if (isset($rows[$idx]))
28
				{
29
					$row = trim($rows[$idx]);
30
					$cols = explode(' ', $row);
31
					for ($c = 0; $c < 3; $c++)
32
						if (isset($cols[$c]))
33
							$build_row[] = floatval(trim($cols[$c]));
34
						else
35
							$build_row[] = $base_row[$c];
36
				}
37
				else
38
					$build_row = $base_row;
39
				
40
				$matrix[] = $build_row;
41
			}
42
			
43
			return $image->applyConvolution($matrix, $this->fval('div'), $this->fval('offset'));
44
		}
45
	}
46