Completed
Push — phoneNumberMatcher ( 6b28c4 )
by Joshua
18:40
created

PhoneNumberMatch   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 84
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A number() 0 4 1
A start() 0 4 1
A end() 0 4 1
A rawString() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace libphonenumber;
4
5
class PhoneNumberMatch
6
{
7
    /**
8
     * The start index into the text.
9
     * @var int
10
     */
11
    private $start;
12
13
    /**
14
     * The raw substring matched.
15
     * @var string
16
     */
17
    private $rawString;
18
19
    /**
20
     * The matched phone number.
21
     * @var PhoneNumber
22
     */
23
    private $number;
24
25
    /**
26
     * Creates a new match
27
     *
28
     * @param int $start The start index into the target text
29
     * @param string $rawString The matched substring of the target text
30
     * @param PhoneNumber $number The matched phone number
31
     * @throws \NullPointerException
32
     */
33
    public function __construct($start, $rawString, PhoneNumber $number)
34
    {
35
        if ($start < 0) {
36
            throw new \InvalidArgumentException("Start index must be >= 0.");
37
        }
38
39
        if ($rawString === null) {
40
            throw new \NullPointerException;
41
        }
42
43
        $this->start = $start;
44
        $this->rawString = $rawString;
45
        $this->number = $number;
46
    }
47
48
    /**
49
     * Returns the phone number matched by the receiver.
50
     * @return PhoneNumber
51
     */
52
    public function number()
53
    {
54
        return $this->number;
55
    }
56
57
    /**
58
     * Returns the start index of the matched phone number within the searched text.
59
     * @return int
60
     */
61
    public function start()
62
    {
63
        return $this->start;
64
    }
65
66
    /**
67
     * Returns the exclusive end index of the matched phone number within the searched text.
68
     * @return int
69
     */
70
    public function end()
71
    {
72
        return $this->start + mb_strlen($this->rawString);
73
    }
74
75
    /**
76
     * Returns the raw string matched as a phone number in the searched text.
77
     * @return string
78
     */
79
    public function rawString()
80
    {
81
        return $this->rawString;
82
    }
83
84
    public function __toString()
85
    {
86
        return "PhoneNumberMatch [{$this->start()},{$this->end()}) {$this->rawString}";
87
    }
88
}
89