EnumMulti   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 53
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 1
A setParameter() 0 9 2
A getMessageParameters() 0 6 1
1
<?php
2
/**
3
 * @package   Fuel\Validation
4
 * @version   2.0
5
 * @author    Fuel Development Team
6
 * @license   MIT License
7
 * @copyright 2010 - 2016 Fuel Development Team
8
 * @link      http://fuelphp.com
9
 */
10
11
namespace Fuel\Validation\Rule;
12
13
use Fuel\Validation\AbstractRule;
14
15
class EnumMulti extends AbstractRule
16
{
17
18
	/**
19
	 * Default failure message
20
	 *
21
	 * @var string
22
	 */
23
	protected $message = 'One or more of the values given are not in the list of allowed values.';
24
25
	/**
26
	 * Sets the values to check against
27
	 *
28
	 * @param string $params
29
	 *
30
	 * @return $this
31
	 *
32
	 * @since 2.0
33
	 */
34 4
	public function setParameter($params)
35
	{
36 4
		if ( ! is_array($params))
37
		{
38 4
			$params = [$params];
39
		}
40
41 4
		return parent::setParameter($params);
42
	}
43
44
	/**
45
	 * Returns
46
	 *
47
	 * array(
48
	 * 		'values' => <target values>
49
	 * );
50
	 *
51
	 * @return string[]
52
	 */
53
	public function getMessageParameters()
54
	{
55
		return array(
56
			'values' => implode('|', $this->getParameter()),
57
		);
58
	}
59
60
	/**
61
	 * {@inheritdoc}
62
	 */
63 3
	public function validate($value, $field = null, $allFields = null)
64
	{
65 3
		return count(array_diff($value, $this->getParameter())) == 0;
66
	}
67
}
68