Completed
Push — master ( dd9cf2...939550 )
by Joshua
13s
created

StrictGrouping   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B verify() 0 18 5
1
<?php
2
3
namespace libphonenumber\Leniency;
4
5
use libphonenumber\PhoneNumber;
6
use libphonenumber\PhoneNumberMatcher;
7
use libphonenumber\PhoneNumberUtil;
8
9
class StrictGrouping extends AbstractLeniency
10
{
11
    protected static $level = 3;
12
13
    /**
14
     * Phone numbers accepted are PhoneNumberUtil::isValidNumber() and are grouped
15
     * in a possible way for this locale. For example, a US number written as
16
     * "65 02 53 00 00" and "650253 0000" are not accepted at this leniency level, whereas
17
     * "650 253 0000", "650 2530000" or "6502530000" are.
18
     * Numbers with more than one '/' symbol in the national significant number are also dropped at
19
     * this level.
20
     *
21
     * Warning: This level might result in lower coverage especially for regions outside of country
22
     * code "+1". If you are not sure about which level to use, email the discussion group
23
     * [email protected].
24
     *
25
     * @param PhoneNumber $number
26
     * @param string $candidate
27
     * @param PhoneNumberUtil $util
28
     * @return bool
29
     */
30 38
    public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $util)
31
    {
32 38
        if (!$util->isValidNumber($number)
33 26
            || !PhoneNumberMatcher::containsOnlyValidXChars($number, $candidate, $util)
34 26
            || PhoneNumberMatcher::containsMoreThanOneSlashInNationalNumber($number, $candidate)
35 38
            || !PhoneNumberMatcher::isNationalPrefixPresentIfRequired($number, $util)
36
        ) {
37 13
            return false;
38
        }
39
40 26
        return PhoneNumberMatcher::checkNumberGroupingIsValid(
41 26
            $number, $candidate, $util,
42 26
            function (PhoneNumberUtil $util, PhoneNumber $number, $normalizedCandidate, $expectedNumberGroups) {
43 26
                return PhoneNumberMatcher::allNumberGroupsRemainGrouped(
44 26
                    $util, $number, $normalizedCandidate, $expectedNumberGroups
45
                );
46 26
            });
47
    }
48
}
49