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

AbstractLeniency   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 5 1
A compareTo() 0 4 1
A getLevel() 0 8 2
A __toString() 0 4 1
1
<?php
2
3
namespace libphonenumber\Leniency;
4
5
use libphonenumber\PhoneNumber;
6
use libphonenumber\PhoneNumberUtil;
7
8
abstract class AbstractLeniency
9
{
10
    /**
11
     * Integer level to compare 'ENUMs'
12
     * @var int
13
     */
14
    protected static $level;
15
16
    /**
17
     * Returns true if $number is a verified number according to this leniency
18
     *
19
     * @param PhoneNumber $number
20
     * @param string $candidate
21
     * @param PhoneNumberUtil $util
22
     * @return bool
23
     */
24
    public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $util)
25
    {
26
        // This can not be called directly
27
        throw new \BadMethodCallException;
28
    }
29
30
    /**
31
     * Compare against another Leniency
32
     * @param AbstractLeniency $leniency
33
     * @return int
34
     */
35
    public static function compareTo(AbstractLeniency $leniency)
36
    {
37
        return static::getLevel() - $leniency::getLevel();
38
    }
39
40
    protected static function getLevel()
41
    {
42
        if (static::$level === null) {
43
            throw new \RuntimeException('$level should not defined');
44
        }
45
46
        return static::$level;
47
    }
48
49
    public function __toString()
50
    {
51
        return str_replace('libphonenumber\\Leniency\\', '', get_class($this));
52
    }
53
}
54