Completed
Push — master ( bb98fa...b1dd66 )
by Beñat
08:36
created

Phone   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A phone() 0 4 1
A equals() 0 4 1
A __toString() 0 4 1
A setPhone() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-2017 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\SharedKernel\Domain\Model\Phone;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
class Phone
18
{
19
    private $phone;
20
21
    public function __construct($phone)
22
    {
23
        $this->phone = $this->setPhone($phone);
24
    }
25
26
    public function phone()
27
    {
28
        return $this->phone;
29
    }
30
31
    public function equals(Phone $phone)
32
    {
33
        return $this->phone === $phone->phone();
34
    }
35
36
    public function __toString()
37
    {
38
        return (string) $this->phone;
39
    }
40
41
    private function setPhone($phone)
42
    {
43
        $phone = str_replace('+34', '', $phone);
44
        $numbers = preg_replace('/\D/', '', $phone);
45
46
        if (!$numbers) {
47
            throw new PhoneInvalidFormatException();
48
        }
49
50
        return $numbers;
51
    }
52
}
53