Completed
Push — master ( 9994ee...95fa60 )
by Konstantin
03:22
created

PhoneHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 53
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 6 1
A removePhoneSpecifications() 0 7 1
A formatPhoneLength() 0 13 3
A get() 0 4 1
1
<?php
2
namespace phrlog\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
        }
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