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

AbstractLeniency::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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