Helpers::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Helpers.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:PhoneUI!
9
 * @subpackage     Templating
10
 * @since          1.0.0
11
 *
12
 * @date           12.12.15
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\PhoneUI\Templating;
18
19
use Nette;
20
21
use Latte\Engine;
22
23
use IPub\Phone;
24
25
/**
26
 * Phone UI number Latte helpers
27
 *
28
 * @package        iPublikuj:PhoneUI!
29
 * @subpackage     Latte
30
 *
31
 * @author         Adam Kadlec <[email protected]>
32
 */
33 1
class Helpers
34
{
35
	/**
36
	 * Implement nette smart magic
37
	 */
38 1
	use Nette\SmartObject;
39
40
	/**
41
	 * @var Phone\Phone
42
	 */
43
	private $phone;
44
45
	/**
46
	 * @param Phone\Phone $phone
47
	 */
48
	public function __construct(Phone\Phone $phone)
49
	{
50 1
		$this->phone = $phone;
51 1
	}
52
53
	/**
54
	 * @param string $phone
55
	 * @param string $country
56
	 * @param int $format
57
	 *
58
	 * @return string
59
	 */
60
	public function phone(
61
		string $phone,
62
		string $country = 'AUTO',
63
		int $format = Phone\Phone::FORMAT_INTERNATIONAL
64
	) : string {
65 1
		$country = strtoupper($country);
66
67 1
		if ((strlen($country) !== 2 || !ctype_alpha($country) || !ctype_upper($country)) && $country !== 'AUTO') {
68
			$format = $country;
69
			$country = 'AUTO';
70
		}
71
72 1
		return $this->phone->format($phone, $country, $format);
73
	}
74
75
	/**
76
	 * @return Phone\Phone
77
	 */
78
	public function getPhoneNumberService() : Phone\Phone
79
	{
80
		return $this->phone;
81
	}
82
}
83