Required   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 34
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 11 7
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 given field exists
17
 *
18
 * @package Fuel\Validation\Rule
19
 * @author  Fuel Development Team
20
 *
21
 * @since   2.0
22
 */
23
class Required extends AbstractRule
24
{
25
26
	/**
27
	 * Contains the rule failure message
28
	 *
29
	 * @var string
30
	 */
31
	protected $message = 'The field is required and has not been specified.';
32
33
	protected $alwaysRun = true;
34
35
	/**
36
	 * @param mixed $value
37
	 * @param null  $field
38
	 * @param null  $allFields
39
	 *
40
	 * @return bool
41
	 *
42
	 * @since 2.0
43
	 */
44 25
	public function validate($value, $field = null, $allFields = null)
45
	{
46
		// Make sure the array key exists in the data
47
		// This check will only be performed if $field and $allFields are set. Else only the value passed will be tested
48 25
		if ( $field === null or ($allFields !== null and ! isset($allFields[$field])))
49
		{
50 14
			return false;
51
		}
52
53 11
		return ($value === 0 or $value === false or ! empty($value) or $value === '0');
54
	}
55
56
}
57