Completed
Push — phoneNumberMatcher ( 6b28c4 )
by Joshua
18:40
created

ExactGrouping::verify()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 2
nop 3
1
<?php
2
3
namespace libphonenumber\Leniency;
4
5
use libphonenumber\PhoneNumber;
6
use libphonenumber\PhoneNumberMatcher;
7
use libphonenumber\PhoneNumberUtil;
8
9
class ExactGrouping extends AbstractLeniency
10
{
11
    protected static $level = 4;
12
13
    /**
14
     * Phone numbers accepted are PhoneNumberUtil::isValidNumber() valid and are grouped
15
     * in the same way that we would have formatted it, or as a single block. For example,
16
     * a US number written as "650 2530000" is not accepted at this leniency level, whereas
17
     * "650 253 0000" or "6502530000" are.
18
     * Numbers with more than one '/' symbol are also dropped at this level.
19
     *
20
     * Warning: This level might result in lower coverage especially for regions outside of country
21
     * code "+1". If you are not sure about which level to use, email the discussion group
22
     * [email protected].
23
     *
24
     * @param PhoneNumber $number
25
     * @param string $candidate
26
     * @param PhoneNumberUtil $util
27
     * @return bool
28
     */
29
    public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $util)
30
    {
31
        if (!$util->isValidNumber($number)
32
            || !PhoneNumberMatcher::containsOnlyValidXChars($number, $candidate, $util)
33
            || PhoneNumberMatcher::containsMoreThanOneSlashInNationalNumber($number, $candidate)
34
            || !PhoneNumberMatcher::isNationalPrefixPresentIfRequired($number, $util)
35
        ) {
36
            return false;
37
        }
38
39
        return PhoneNumberMatcher::checkNumberGroupingIsValid($number, $candidate, $util,
40
            function (PhoneNumberUtil $util, PhoneNumber $number, $normalizedCandidate, $expectedNumberGroups) {
41
                return PhoneNumberMatcher::allNumberGroupsAreExactlyPresent(
42
                    $util, $number, $normalizedCandidate, $expectedNumberGroups
43
                );
44
            });
45
    }
46
}
47