RequiredIf::validate()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 5
cts 5
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 2
nop 3
crap 4
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
/**
14
 * Checks that the given field exists if the conditional field is passed and is not empty
15
 *
16
 * @package Fuel\Validation\Rule
17
 * @author  Fuel Development Team
18
 *
19
 * @since   2.0
20
 */
21 View Code Duplication
class RequiredIf extends Required
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...
22
{
23
24
	/**
25
	 * @param mixed $value
26
	 * @param null  $field
27
	 * @param null  $allFields
28
	 *
29
	 * @return bool
30
	 *
31
	 * @since 2.0
32
	 */
33 4
	public function validate($value, $field = null, $allFields = null)
34
	{
35 4
		$requiredField = $this->getParameter();
36
37 4
		if ($allFields !== null and array_key_exists($requiredField, $allFields) and ! empty($allFields[$requiredField]))
38
		{
39 2
			return parent::validate($value, $field, $allFields);
40
		}
41
42 2
		return true;
43
	}
44
45
}
46