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

Validator::setParameter()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
crap 3
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