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

RegexBasedMatcher::matchesPossibleNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
eloc 3
nc 1
nop 2
crap 2
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