RequiredIf   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 25
loc 25
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 11 11 4

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
/**
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