Completed
Push — develop ( 755a17...843010 )
by Daniel
07:33
created

telephone::display_field()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 2
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 telephone extends base
13
{
14
	/**
15
	 * @inheritdoc
16
	 */
17 4
	public function get_name()
18
	{
19 4
		return 'telephone';
20
	}
21
22
	/**
23
	 * @inheritdoc
24
	 */
25 3
	public function get_default_props()
26
	{
27
		return array(
28 3
			'min'	=> 0,
29 3
			'max'	=> 200,
30 3
			'size'	=> 10,
31 3
		);
32
	}
33
34
	/**
35
	 * @inheritdoc
36
	 */
37 2
	public function display_field(array $data)
38
	{
39 2
		return $data['field_value'] ? '<a href="tel:' . $data['field_value'] . '">' . preg_replace("/^1?(\d{3})(\d{3})(\d{4})$/", "$1-$2-$3", $data['field_value']) . '</a>' : '';
40
	}
41
42
	/**
43
	 * @inheritdoc
44
	 */
45 2
	public function get_field_value($name, $value)
46
	{
47 2
		$value = $this->request->variable($name, (int) $value);
48 2
		return ($value) ? $value : '';
49
	}
50
}
51