LengthException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 9
c 2
b 1
f 0
dl 0
loc 54
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLength() 0 3 1
A __toString() 0 3 1
A __construct() 0 8 1
1
<?php
2
3
/**
4
 * ~~summary~~
5
 *
6
 * ~~description~~
7
 *
8
 * PHP version 5
9
 *
10
 * @category  Net
11
 * @package   PEAR2_Net_RouterOS
12
 * @author    Vasil Rangelov <[email protected]>
13
 * @copyright 2011 Vasil Rangelov
14
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
15
 * @version   GIT: $Id$
16
 * @link      http://pear2.php.net/PEAR2_Net_RouterOS
17
 */
18
/**
19
 * The namespace declaration.
20
 */
21
namespace PEAR2\Net\RouterOS;
22
23
/**
24
 * Base of this class.
25
 */
26
use LengthException as L;
27
28
/**
29
 * Used in $previous
30
 */
31
use Exception as E;
32
33
/**
34
 * Exception thrown when there is a problem with a word's length.
35
 *
36
 * @category Net
37
 * @package  PEAR2_Net_RouterOS
38
 * @author   Vasil Rangelov <[email protected]>
39
 * @license  http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
40
 * @link     http://pear2.php.net/PEAR2_Net_RouterOS
41
 */
42
class LengthException extends L implements Exception
43
{
44
45
    const CODE_UNSUPPORTED = 1200;
46
    const CODE_INVALID = 1300;
47
    const CODE_BEYOND_SHEME = 1301;
48
49
    /**
50
     * The problematic length.
51
     *
52
     * @var int|double|null
53
     */
54
    private $_length;
55
56
    /**
57
     * Creates a new LengthException.
58
     *
59
     * @param string          $message  The Exception message to throw.
60
     * @param int             $code     The Exception code.
61
     * @param E|null          $previous The previous exception used for the
62
     *     exception chaining.
63
     * @param int|double|null $length   The length.
64
     */
65
    public function __construct(
66
        $message,
67
        $code = 0,
68
        E $previous = null,
69
        $length = null
70
    ) {
71
        parent::__construct($message, $code, $previous);
72
        $this->_length = $length;
73
    }
74
75
    /**
76
     * Gets the length.
77
     *
78
     * @return int|double|null The length.
79
     */
80
    public function getLength()
81
    {
82
        return $this->_length;
83
    }
84
85
    // @codeCoverageIgnoreStart
86
    // String representation is not reliable in testing
87
88
    /**
89
     * Returns a string representation of the exception.
90
     *
91
     * @return string The exception as a string.
92
     */
93
    public function __toString()
94
    {
95
        return parent::__toString() . "\nLength:{$this->_length}";
96
    }
97
98
    // @codeCoverageIgnoreEnd
99
}
100