Date   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 64
ccs 13
cts 13
cp 1
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B validate() 0 20 5
A getMessageParameters() 0 9 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
15
/**
16
 * Checks that the value is a valid date
17
 *
18
 * @package Fuel\Validation\Rule
19
 * @author  Fuel Development Team
20
 *
21
 * @since 2.0
22
 */
23
class Date extends AbstractRule
24
{
25
26
	/**
27
	 * Contains the rule failure message
28
	 *
29
	 * @var string
30
	 */
31
	protected $message = 'The field does not contain a valid date.';
32
33
	/**
34
	 * @param mixed $value Value to be validated
35
	 * @param null  $field Unused by this rule
36
	 * @param null  $allFields
37
	 *
38
	 * @internal param null $allFields Unused by this rule
39
	 *
40
	 * @return bool
41
	 *
42
	 * @since 2.0
43
	 */
44 26
	public function validate($value, $field = null, $allFields = null)
45
	{
46 26
		$parameters = $this->getParameter();
47 26
		$format = $parameters['format'];
48
49 26
		if ( (is_object($value) and ! method_exists($value, '__toString')) or $this->getParameter() === null )
50
		{
51 3
			return false;
52
		}
53
54 23
		if ( ! $format )
55
		{
56 9
			return false;
57
		}
58
59 14
		$date = date_parse_from_format($format, (string) $value);
60
61 14
		return ( $date['error_count'] + $date['warning_count'] === 0 );
62
63
	}
64
65
	/**
66
	 * Returns
67
	 *
68
	 * array(
69
	 *      'format' => <format value>
70
	 * );
71
	 *
72
	 * @return array
73
	 *
74
	 * @since 2.0
75
	 */
76 1
	public function getMessageParameters()
77
	{
78 1
		$parameters = $this->getParameter();
79 1
		$format = $parameters['format'];
80
81
		return array(
82 1
			'format' => $format,
83
		);
84
	}
85
86
}
87