Completed
Push — master ( 71957b...519609 )
by Joshua
16:17
created

RegexBasedMatcher::matchesNationalNumber()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 3
eloc 4
nc 3
nop 3
crap 3.576
1
<?php
2
3
namespace libphonenumber;
4
5
class RegexBasedMatcher implements MatcherAPIInterface
6
{
7
    public static function create()
8
    {
9
        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 85
    public function matchesNationalNumber($nationalNumber, PhoneNumberDesc $numberDesc, $allowPrefixMatch)
22
    {
23
        $nationalNumberPatternMatcher = new Matcher($numberDesc->getNationalNumberPattern(), $nationalNumber);
24
25
        return ($nationalNumberPatternMatcher->matches()
26 85
            || ($allowPrefixMatch && $nationalNumberPatternMatcher->lookingAt()));
27 85
    }
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 14
    public function matchesPossibleNumber($nationalNumber, PhoneNumberDesc $numberDesc)
38
    {
39
        $possibleNumberPatternMatcher = new Matcher($numberDesc->getPossibleNumberPattern(), $nationalNumber);
40
41
        return $possibleNumberPatternMatcher->matches();
42 14
    }
43
}
44