Completed
Push — dev-7.6.1 ( 6fa1d9...762c00 )
by Joshua
49:26 queued 32:55
created

RegexBasedMatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A matchesNationalNumber() 0 7 3
A matchesPossibleNumber() 0 6 1
1
<?php
2
3
namespace libphonenumber;
4
5
class RegexBasedMatcher implements MatcherAPIInterface
6
{
7 28
    public static function create()
8
    {
9 28
        return new static();
10
    }
11
12
    /**
13
     * Returns whether the given national number (a string containing only decimal digits) matches
14
     * the national number pattern defined in the given {@code PhoneNumberDesc} message.
15
     *
16
     * @param string $nationalNumber
17
     * @param PhoneNumberDesc $numberDesc
18
     * @param boolean $allowPrefixMatch
19
     * @return boolean
20
     */
21 616
    public function matchesNationalNumber($nationalNumber, PhoneNumberDesc $numberDesc, $allowPrefixMatch)
22
    {
23 616
        $nationalNumberPatternMatcher = new Matcher($numberDesc->getNationalNumberPattern(), $nationalNumber);
24
25 616
        return ($nationalNumberPatternMatcher->matches()
26 616
            || ($allowPrefixMatch && $nationalNumberPatternMatcher->lookingAt()));
27
    }
28
29
    /**
30
     * Returns whether the given national number (a string containing only decimal digits) matches
31
     * the possible number pattern defined in the given {@code PhoneNumberDesc} message.
32
     *
33
     * @param string $nationalNumber
34
     * @param PhoneNumberDesc $numberDesc
35
     * @return boolean
36
     */
37 586
    public function matchesPossibleNumber($nationalNumber, PhoneNumberDesc $numberDesc)
38
    {
39 586
        $possibleNumberPatternMatcher = new Matcher($numberDesc->getPossibleNumberPattern(), $nationalNumber);
40
41 586
        return $possibleNumberPatternMatcher->matches();
42
    }
43
}
44