ExactGrouping   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

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