NumericMin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 68
loc 68
ccs 11
cts 11
cp 1
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 11 11 3
A setParameter() 10 10 2
A getMessageParameters() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @package   Fuel\Validation
4
 * @version   2.0
5
 * @author    Fuel Development Team
6
 * @license   MIT License
7
 * @copyright 2010 - 2013 Fuel Development Team
8
 * @link      http://fuelphp.com
9
 */
10
11
namespace Fuel\Validation\Rule;
12
13
use Fuel\Validation\AbstractRule;
14
15
/**
16
 * Checks that the value is greater than or equal to a value
17
 *
18
 * @package Fuel\Validation\Rule
19
 * @author  Fuel Development Team
20
 * @since   2.0
21
 */
22 View Code Duplication
class NumericMin extends AbstractRule
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
25
	/**
26
	 * Contains the rule failure message
27
	 *
28
	 * @var string
29
	 */
30
	protected $message = 'The field is not equal to or greater than the specified value.';
31
32
	/**
33
	 * @param mixed  $value Value to validate
34
	 * @param string $field Unused by this rule
35
	 * @param array  $allFields Unused by this rule
36
	 *
37
	 * @return bool
38
	 *
39
	 * @since 2.0
40
	 */
41 15
	public function validate($value, $field = null, $allFields = null)
42
	{
43 15
		$min = $this->getParameter();
44
45 15
		if ($min === null or ! is_numeric($value))
46
		{
47 4
			return false;
48
		}
49
50 11
		return $value >= $min;
51
	}
52
53
	/**
54
	 * Sets the value to check against
55
	 *
56
	 * @param string $params If an array the first value will be used
57
	 *
58
	 * @return $this
59
	 *
60
	 * @since 2.0
61
	 */
62 18
	public function setParameter($params)
63
	{
64
		// Ensure we have only a single thing to match against
65 18
		if (is_array($params))
66
		{
67 1
			$params = array_shift($params);
68
		}
69
70 18
		return parent::setParameter($params);
71
	}
72
73
	/**
74
	 * Returns
75
	 *
76
	 * array(
77
	 * 		'minValue' => <target value>
78
	 * );
79
	 *
80
	 * @return string[]
81
	 */
82 1
	public function getMessageParameters()
83
	{
84
		return array(
85 1
			'minValue' => $this->getParameter(),
86
		);
87
	}
88
89
}
90