Completed
Push — count-subquery-clone ( d5815f...6cc328 )
by Haralan
03:48
created

Kohana_Jam_Validator_Rule_Count::validate()   D

Complexity

Conditions 10
Paths 16

Size

Total Lines 28
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 10

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
rs 4.8196
ccs 20
cts 20
cp 1
cc 10
eloc 11
nc 16
nop 3
crap 10

How to fix   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 defined('SYSPATH') OR die('No direct script access.');
2
/**
3
 * Jam Validatior Rule
4
 *
5
 * @package    Jam
6
 * @category   Validation
7
 * @author     Ivan Kerin
8
 * @copyright  (c) 2011-2012 Despark Ltd.
9
 * @license    http://www.opensource.org/licenses/isc-license.txt
10
 */
11
class Kohana_Jam_Validator_Rule_Count extends Jam_Validator_Rule {
12
13
	public $minimum;
14
15
	public $maximum;
16
17
	public $within;
18
19
	public $is;
20
21 16
	public function validate(Jam_Validated $model, $attribute, $value)
22
	{
23 16
		$count = count($value);
24 16
		$params = (array) $this;
0 ignored issues
show
Unused Code introduced by
$params 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
26 16
		if ($this->minimum !== NULL AND ! ($count >= $this->minimum))
27 16
		{
28 2
			$model->errors()->add($attribute, 'count_minimum', array(':minimum' => $this->minimum));
0 ignored issues
show
Bug introduced by
The method add cannot be called on $model->errors() (of type array|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
29 2
		}
30
31 16
		if ($this->maximum !== NULL AND ! ($count <= $this->maximum))
32 16
		{
33 2
			$model->errors()->add($attribute, 'count_maximum', array(':maximum' => $this->maximum));
0 ignored issues
show
Bug introduced by
The method add cannot be called on $model->errors() (of type array|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34 2
		}
35
36 16
		if ($this->within !== NULL AND ! ($count >= $this->within[0] AND $count <= $this->within[1]))
37 16
		{
38 4
			$model->errors()->add($attribute, 'count_within', array(':minimum' => $this->within[0], ':maximum' => $this->within[1]));
0 ignored issues
show
Bug introduced by
The method add cannot be called on $model->errors() (of type array|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
39 4
		}
40
41 16
		if ($this->is !== NULL AND ! ($count == $this->is))
42 16
		{
43 3
			$model->errors()->add($attribute, 'count_is', array(':is' => $this->is));
0 ignored issues
show
Bug introduced by
The method add cannot be called on $model->errors() (of type array|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
44 3
		}
45
46
47
48 16
	}
49
}
50