Completed
Push — dev-7.6.1 ( 6fa1d9...762c00 )
by Joshua
49:26 queued 32:55
created

NumberParseException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrorType() 0 4 1
A __toString() 0 4 1
A __construct() 0 6 1
1
<?php
2
3
namespace libphonenumber;
4
5
/**
6
 * Generic exception class for errors encountered when parsing phone numbers.
7
 * @author Lara Rennie
8
 */
9
class NumberParseException extends \Exception
10
{
11
    const INVALID_COUNTRY_CODE = 0;
12
    // This generally indicates the string passed in had less than 3 digits in it. More
13
    // specifically, the number failed to match the regular expression VALID_PHONE_NUMBER in
14
    // PhoneNumberUtil.
15
    const NOT_A_NUMBER = 1;
16
    // This indicates the string started with an international dialing prefix, but after this was
17
    // stripped from the number, had less digits than any valid phone number (including country
18
    // code) could have.
19
    const TOO_SHORT_AFTER_IDD = 2;
20
    // This indicates the string, after any country code has been stripped, had less digits than any
21
    // valid phone number could have.
22
    const TOO_SHORT_NSN = 3;
23
    // This indicates the string had more digits than any valid phone number could have.
24
    const TOO_LONG = 4;
25
26
    protected $errorType;
27
28 12
    public function __construct($errorType, $message, $previous = null)
29
    {
30 12
        parent::__construct($message, $errorType, $previous);
31 12
        $this->message = $message;
32 12
        $this->errorType = $errorType;
33 12
    }
34
35
    /**
36
     * Returns the error type of the exception that has been thrown.
37
     */
38 8
    public function getErrorType()
39
    {
40 8
        return $this->errorType;
41
    }
42
43 2
    public function __toString()
44
    {
45 2
        return "Error type: " . $this->errorType . ". " . $this->message;
46
    }
47
}
48