Passed
Push — develop ( 77e6e2...97cb86 )
by Daniel
03:55
created

number::get_error_message()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 9
ccs 0
cts 0
cp 0
crap 12
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services\form\field;
11
12
class number extends base
13
{
14
	/**
15
	 * @inheritdoc
16
	 */
17 3
	public function get_name()
18
	{
19 3
		return 'number';
20
	}
21
22
	/**
23
	 * @inheritdoc
24
	 */
25 4
	public function get_default_props()
26
	{
27
		return array(
28 4
			'min'	=> 0,
29 4
			'max'	=> 0,
30 4
			'step'	=> 1,
31 4
			'size'	=> 10,
32 4
		);
33
	}
34
35
	/**
36
	 * @inheritdoc
37
	 */
38 10
	public function get_validation_rules(array $data)
39
	{
40 10
		return array(
41
			'filter'	=> (is_float($data['field_props']['step'])) ? FILTER_VALIDATE_FLOAT : FILTER_VALIDATE_INT,
42
			'options'	=> array(
43
				'options'	=> array_filter(array(
44
					'min_range'	=> $data['field_props']['min'],
45
					'max_range'	=> $data['field_props']['max'],
46
					'decimal'	=> '.',
47
				)),
48
				'flags'	=> FILTER_FLAG_ALLOW_THOUSAND,
49
			),
50
		);
51
	}
52
53
	/**
54
	 * @inheritdoc
55
	 */
56
	public function get_error_message(array $data)
57
	{
58
		$props = $data['field_props'];
59
		$lang_keys = array('FIELD_INVALID');
60
61
		$lang_keys[] = ($props['min']) ? 'MIN' : '';
62
		$lang_keys[] = ($props['max']) ? 'MAX' : '';
63
64
		return $this->language->lang(join('_', array_filter($lang_keys)), $data['field_label'], $props['min'], $props['max']);
65
	}
66
67
	/**
68
	 * @inheritdoc
69
	 */
70
	public function get_field_value(array $data)
71
	{
72
		return $this->request->variable($data['field_name'], (int) $data['field_value']);
73
	}
74
}
75