Completed
Push — master ( 731a89...d11137 )
by Steve
04:30
created

Validator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 34
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setParameter() 0 8 3
A validate() 0 7 1
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
use Fuel\Validation\AbstractRule;
14
use Fuel\Validation\ValidatableInterface;
15
use InvalidArgumentException;
16
17
/**
18
 * Allows validation of nested data structures.
19
 *
20
 * @package Fuel\Validation\Rule
21
 * @author  Fuel Development Team
22
 *
23
 * @since   2.0
24
 */
25
class Validator extends AbstractRule
26
{
27
28
	/**
29
	 * {@inheritdoc}
30
	 */
31
	protected $message = 'The child model is invalid.';
32
33
	/**
34
	 * @param ValidatableInterface $params
35
	 *
36
	 * @return $this
37
	 */
38 3
	public function setParameter($params)
39
	{
40 3
		if ( $params !== null && ! $params instanceof ValidatableInterface) {
41 1
			throw new InvalidArgumentException('VAL-009: Provided parameter does not implement ValidatableInterface');
42
		}
43
44 3
		return parent::setParameter($params);
45
	}
46
47
	/**
48
	 * {@inheritdoc}
49
	 */
50 1
	public function validate($value, $field = null, $allFields = null)
51
	{
52
		/** @var ValidatableInterface $validator */
53 1
		$validator = $this->getParameter();
54
55 1
		return $validator->run($value);
56
	}
57
58
}
59