Options::test()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 5
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of the Joomla Framework Form Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
7
 */
8
9
namespace Joomla\Form\Rule;
10
11
use Joomla\Form\Rule;
12
use Joomla\Form\Form;
13
use Joomla\Registry\Registry;
14
use SimpleXMLElement;
15
16
/**
17
 * Form Rule class for the Joomla Framework.
18
 * Requires the value entered be one of the options in a field of type="list"
19
 *
20
 * @since       1.0
21
 * @deprecated  The joomla/form package is deprecated
22
 */
23
class Options extends Rule
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule has been deprecated with message: The joomla/form package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
{
25
	/**
26
	 * Method to test the value.
27
	 *
28
	 * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
29
	 * @param   mixed             $value    The form field value to validate.
30
	 * @param   string            $group    The field name group control value. This acts as as an array container for the field.
31
	 *                                      For example if the field has name="foo" and the group value is set to "bar" then the
32
	 *                                      full field name would end up being "bar[foo]".
33
	 * @param   Registry          $input    An optional Registry object with the entire data set to validate against the entire form.
34
	 * @param   Form              $form     The form object for which the field is being tested.
35
	 *
36
	 * @return  boolean  True if the value is valid, false otherwise.
37
	 *
38
	 * @since   1.0
39
	 */
40
	public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
41
	{
42
		// Check each value and return true if we get a match
43
		foreach ($element->option as $option)
44
		{
45
			if ($value == (string) $option->attributes()->value)
46
			{
47
				return true;
48
			}
49
		}
50
51
		return false;
52
	}
53
}
54