Validation_callbacks   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 70.83%

Importance

Changes 0
Metric Value
dl 0
loc 73
ccs 17
cts 24
cp 0.7083
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A due_date() 0 13 3
A valid_email() 0 11 2
A reminder_due() 0 11 2
1
<?php
2
3
/**
4
 * Form validation callbacks
5
 */
6
class Validation_callbacks {
7
8
	/**
9
	 * CodeIgniter Instance
10
	 *
11
	 * @var MY_Controller
12
	 */
13
	protected $CI;
14
15
	/**
16
	 * Constructor
17
	 */
18 2
	public function __construct()
19
	{
20 2
		$this->CI =& get_instance();
21 2
	}
22
23
	/**
24
	 * Validate the format of the due date field
25
	 *
26
	 * @param string $due
27
	 * @return bool
28
	 */
29 7
	public function due_date($due)
30
	{
31
		//Verify date format
32 7
		$date_pattern = '/(20|1[0-9])[0-9]{2}\-(1[0-2]|0[1-9])\-(3[0-1]|2[0-8]|1[0-9]|0[1-9])/';
33
34 7
		if ( ! (bool) preg_match($date_pattern, $due) && $due != 0)
35 7
		{
36 1
			$this->CI->form_validation->set_message('validate', 'You must enter a due date in YYYY-MM-DD format.');
37 1
			return FALSE;
38
		}
39
40 6
		return TRUE;
41
	}
42
43
	/**
44
	 * Verify that an email address is valid
45
	 *
46
	 * @param string $email
47
	 * @return bool
48
	 */
49 5
	public function valid_email($email)
50
	{
51 5
		$valid = filter_var($email, FILTER_VALIDATE_EMAIL);
52
53 5
		if ( ! $valid)
54 5
		{
55 1
			$this->CI->form_validation->set_message('validate', 'You must enter a valid email address.');
56 1
		}
57
58 5
		return $valid;
59
	}
60
61
	/**
62
	 * Verify that a reminder has a valid due date
63
	 *
64
	 * @param string $date
65
	 * @return bool
66
	 */
67
	public function reminder_due($date)
68
	{
69
		$has_date = ($date != '0');
70
71
		if ( ! $has_date)
72
		{
73
			$this->CI->form_validation->set_message('validate', 'You must set a due date in order to get a reminder.');
74
		}
75
76
		return $has_date;
77
	}
78
}
79
// End of libraries/Validation_callbacks.php