Field   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 118
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setLabel() 0 6 1
A setName() 0 6 1
A getName() 0 4 1
A addRule() 0 6 1
A getRules() 0 4 1
A getLabel() 0 9 2
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;
12
13
/**
14
 * Defines a field that can be validated
15
 *
16
 * @package Fuel\Validation
17
 * @author  Fuel Development Team
18
 *
19
 * @since 2.0
20
 */
21
class Field implements FieldInterface
22
{
23
24
	/**
25
	 * @var string
26
	 */
27
	protected $name;
28
29
	/**
30
	 * @var string
31
	 */
32
	protected $label;
33
34
	/**
35
	 * @var RuleInterface[]
36
	 */
37
	protected $rules = [];
38
39
	/**
40
	 * @param string $name
41
	 * @param string $friendlyName
42
	 */
43 26
	public function __construct($name = null, $friendlyName = null)
44
	{
45 26
		$this->setName($name);
46 26
		$this->setLabel($friendlyName);
47 26
	}
48
49
	/**
50
	 * Sets the label of this field
51
	 *
52
	 * @param string $friendlyName
53
	 *
54
	 * @return $this
55
	 *
56
	 * @since 2.0
57
	 */
58 26
	public function setLabel($friendlyName)
59
	{
60 26
		$this->label = $friendlyName;
61
62 26
		return $this;
63
	}
64
65
	/**
66
	 * Gets the label of this field
67
	 *
68
	 * @return string
69
	 *
70
	 * @since 2.0
71
	 */
72 10
	public function getLabel()
73
	{
74 10
		if ($this->label === null)
75
		{
76 7
			return $this->getName();
77
		}
78
79 3
		return $this->label;
80
	}
81
82
	/**
83
	 * Sets the machine name of this field
84
	 *
85
	 * @param string $name
86
	 *
87
	 * @return $this
88
	 *
89
	 * @since 2.0
90
	 */
91 26
	public function setName($name)
92
	{
93 26
		$this->name = $name;
94
95 26
		return $this;
96
	}
97
98
	/**
99
	 * Gets the machine name of this field
100
	 *
101
	 * @return string
102
	 *
103
	 * @since 2.0
104
	 */
105 24
	public function getName()
106
	{
107 24
		return $this->name;
108
	}
109
110
	/**
111
	 * Sets a rule to validate this field with
112
	 *
113
	 * @param RuleInterface $rule
114
	 *
115
	 * @return $this
116
	 *
117
	 * @since 2.0
118
	 */
119 20
	public function addRule(RuleInterface $rule)
120
	{
121 20
		$this->rules[] = $rule;
122
123 20
		return $this;
124
	}
125
126
	/**
127
	 * Returns a list of rules that will be used to validate this field
128
	 *
129
	 * @return RuleInterface[]
130
	 *
131
	 * @since 2.0
132
	 */
133 19
	public function getRules()
134
	{
135 19
		return $this->rules;
136
	}
137
138
}
139