MY_Controller::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
/**
4
 * Base controller extending CodeIgniter Controller
5
 */
6
class MY_Controller extends CI_Controller {
7
	/**
8
	 * @var Validation_Callbacks
9
	 */
10
	public $validation_callbacks;
11
12
	/**
13
	 * @var Page
14
	 */
15
	public $page;
16
17
	// --------------------------------------------------------------------------
18
19
	/**
20
	 * Validate a form field using a callback
21
	 *
22
	 * @param string $str
23
	 * @param string $rule_name
24
	 * @return mixed
25
	 * @throws InvalidArgumentException
26
	 */
27 13
	public function validate($str, $rule_name)
28
	{
29 13
		if (method_exists($this->validation_callbacks, $rule_name))
30 13
		{
31 12
			return $this->validation_callbacks->$rule_name($str);
32
		}
33
34 1
		throw new InvalidArgumentException("Validation callback '{$rule_name}' does not exist");
35
	}
36
}
37
// End of core/MY_Controller.php