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

text   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get_error_message() 0 3 1
A get_name() 0 3 1
A get_default_props() 0 5 1
A is_valid() 0 8 3
A get_validation_rules() 0 8 1
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 text extends base
13
{
14
	/** @var int */
15
	protected $maxlength = 0;
16
17 8
	/**
18
	 * @inheritdoc
19 8
	 */
20
	public function get_name()
21
	{
22
		return 'text';
23
	}
24
25 5
	/**
26
	 * @inheritdoc
27
	 */
28 5
	public function get_default_props()
29 5
	{
30 5
		return array(
31
			'maxlength'	=> 255,
32
			'size'		=> 40,
33
		);
34
	}
35
36
	/**
37
	 * @inheritdoc
38
	 */
39
	public function get_validation_rules(array $data)
40
	{
41
		$this->maxlength = $data['field_props']['maxlength'];
42
43
		return array(
44
			'filter'	=> FILTER_CALLBACK,
45
			'options'	=> array(
46
				'options'	=> array($this, 'is_valid'),
47
			),
48
		);
49
	}
50
51
	/**
52
	 * @param string $value
53
	 * @return false|string
54
	 */
55
	protected function is_valid($value)
56
	{
57
		if ($this->maxlength && utf8_strlen($value) > $this->maxlength)
0 ignored issues
show
Bug introduced by
The function utf8_strlen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
		if ($this->maxlength && /** @scrutinizer ignore-call */ utf8_strlen($value) > $this->maxlength)
Loading history...
58
		{
59
			return false;
60
		}
61
62
		return $value;
63
	}
64
65
	/**
66
	 * @inheritdoc
67
	 */
68
	public function get_error_message(array $data)
69
	{
70
		return $this->language->lang('FIELD_TOO_LONG', $data['field_label'], $this->maxlength);
71
	}
72
}
73