Completed
Push — master ( 1f4d4b...a8745e )
by Konstantin
01:37
created

PhoneHelper::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 3
nop 1
crap 1
1
<?php
2
namespace FormHelper;
3
4
/**
5
 * Class PhoneHelper
6
 * @package FormHelper
7
 */
8
class PhoneHelper extends AbstractFormHelper
9
{
10
    private $phone;
11
12
    /**
13
     * @param $phone
14
     * @return $this
15
     */
16 3
    public function set($phone)
17
    {
18 3
        $this->phone = (string) $phone;
19
20 3
        return $this;
21
    }
22
23
    /**
24
     * @return $this
25
     */
26 3
    public function removePhoneSpecifications()
27
    {
28 3
        $trans = ['(' => '', ')' => '', '-' => '', '+' => '', ' '  => ''];
29 3
        $this->phone = strtr($this->phone, $trans);
30
31 3
        return $this;
32
    }
33
34
    /**
35
     * @param $length
36
     * @return $this
37
     */
38 3
    public function formatPhoneLength($length = 10)
39
    {
40 3
        $phone_length = strlen($this->phone);
41 3
        $phone_diff = $phone_length - $length;
42
43 3
        if ($phone_diff == 1) {
44 1
            $this->phone = mb_substr($this->phone, 1);
45 3
        } elseif ($phone_diff !== 0) {
46 1
            $this->phone = false;
47 1
        }
48
49 3
        return $this;
50
    }
51
52
    /**
53
     * @return mixed
54
     */
55 3
    public function get()
56
    {
57 3
        return $this->phone;
58
    }
59
60
}
61