Completed
Pull Request — master (#164)
by Joshua
09:55
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
     * @codeCoverageIgnore
24
     */
25
    public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $util)
26
    {
27
        // This can not be called directly
28
        throw new \BadMethodCallException;
29
    }
30
31
    /**
32
     * Compare against another Leniency
33
     * @param AbstractLeniency $leniency
34
     * @return int
35
     */
36
    public static function compareTo(AbstractLeniency $leniency)
37
    {
38
        return static::getLevel() - $leniency::getLevel();
39
    }
40
41
    protected static function getLevel()
42
    {
43
        if (static::$level === null) {
44
            throw new \RuntimeException('$level should be defined');
45
        }
46
47
        return static::$level;
48
    }
49
50
    public function __toString()
51
    {
52
        return str_replace('libphonenumber\\Leniency\\', '', get_class($this));
53
    }
54
}
55