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

RegexBasedMatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 71.43%

Importance

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

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
    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