Completed
Push — master ( d5c9e6...77b81f )
by Konstantin
02:19
created

PhoneHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 55
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 6 1
A removePhoneSpecifications() 0 7 1
A formatPhoneLength() 0 15 3
A get() 0 4 1
1
<?php
2
namespace FormHelper;
3
4
5
class PhoneHelper extends AbstractFormHelper
6
{
7
    private $phone;
8
9
    /**
10
     * @param $phone
11
     * @return $this
12
     */
13 2
    public function set($phone)
14
    {
15 2
        $this->phone = (string) $phone;
16
17 2
        return $this;
18
    }
19
20
    /**
21
     * @return $this
22
     */
23 2
    public function removePhoneSpecifications()
24
    {
25 2
        $trans = ['(' => '', ')' => '', '-' => '', '+' => '', ' '  => ''];
26 2
        $this->phone = strtr($this->phone, $trans);
27
28 2
        return $this;
29
    }
30
31
    /**
32
     * @param $length
33
     * @return $this|bool
34
     */
35 2
    public function formatPhoneLength($length = 10)
36
    {
37 2
        $phone_length = strlen($this->phone);
38 2
        $phone_diff = $phone_length - $length;
39
40 2
        if ($phone_diff == 0) {
41 2
            return $this;
42 1
        } elseif($phone_diff == 1) {
43 1
            $this->phone = mb_substr($this->phone, 1);
44 1
            return $this;
45
        } else {
46
            $this->phone = false;
47
            return $this;
48
        }
49
    }
50
51
    /**
52
     * @return mixed
53
     */
54 2
    public function get()
55
    {
56 2
        return $this->phone;
57
    }
58
59
}
60
61