Completed
Pull Request — master (#145)
by Graham
09:30
created

RegexBasedMatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

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

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 623
    public function matchesNationalNumber($nationalNumber, PhoneNumberDesc $numberDesc, $allowPrefixMatch)
22
    {
23 623
        $nationalNumberPatternMatcher = new Matcher($numberDesc->getNationalNumberPattern(), $nationalNumber);
24
25 623
        return ($nationalNumberPatternMatcher->matches()
26 623
            || ($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
    public function matchesPossibleNumber($nationalNumber, PhoneNumberDesc $numberDesc)
38
    {
39
        $possibleNumberPatternMatcher = new Matcher($numberDesc->getPossibleNumberPattern(), $nationalNumber);
40
41
        return $possibleNumberPatternMatcher->matches();
42
    }
43
}
44