StrictGrouping   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A verify() 0 20 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 39
    public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $util)
31
    {
32 39
        if (!$util->isValidNumber($number)
33 27
            || !PhoneNumberMatcher::containsOnlyValidXChars($number, $candidate, $util)
34 27
            || PhoneNumberMatcher::containsMoreThanOneSlashInNationalNumber($number, $candidate)
35 39
            || !PhoneNumberMatcher::isNationalPrefixPresentIfRequired($number, $util)
36
        ) {
37 14
            return false;
38
        }
39
40 27
        return PhoneNumberMatcher::checkNumberGroupingIsValid(
41 27
            $number,
42 27
            $candidate,
43 27
            $util,
44
            function (PhoneNumberUtil $util, PhoneNumber $number, $normalizedCandidate, $expectedNumberGroups) {
45 27
                return PhoneNumberMatcher::allNumberGroupsRemainGrouped(
46 27
                    $util,
47 27
                    $number,
48 27
                    $normalizedCandidate,
49 27
                    $expectedNumberGroups
50
                );
51 27
            }
52
        );
53
    }
54
}
55