Completed
Push — develop ( 5ed1fa...10f0a8 )
by Vasil
06:12
created

RouterErrorException::getResponses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 RuntimeException;
27
28
/**
29
 * Exception thrown by higher level classes (Util, etc.) when the router
30
 * returns an error.
31
 *
32
 * @category Net
33
 * @package  PEAR2_Net_RouterOS
34
 * @author   Vasil Rangelov <[email protected]>
35
 * @license  http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
36
 * @link     http://pear2.php.net/PEAR2_Net_RouterOS
37
 */
38
class RouterErrorException extends RuntimeException implements Exception
39
{
40
    const CODE_ITEM_ERROR           = 0x100000;
41
    const CODE_SCRIPT_ERROR         = 0x200000;
42
    const CODE_READ_ERROR           = 0x010000;
43
    const CODE_WRITE_ERROR          = 0x020000;
44
    const CODE_EXEC_ERROR           = 0x040000;
45
46
    const CODE_CACHE_ERROR          = 0x100001;
47
    const CODE_GET_ERROR            = 0x110001;
48
    const CODE_GETALL_ERROR         = 0x110002;
49
    const CODE_ADD_ERROR            = 0x120001;
50
    const CODE_SET_ERROR            = 0x120002;
51
    const CODE_REMOVE_ERROR         = 0x120004;
52
    const CODE_SCRIPT_GET_ERROR     = 0x210001;
53
    const CODE_SCRIPT_ADD_ERROR     = 0x220001;
54
    const CODE_SCRIPT_REMOVE_ERROR  = 0x220004;
55
    const CODE_SCRIPT_RUN_ERROR     = 0x240001;
56
57
    /**
58
     * @var ResponseCollection|null The complete response returned by the router.
59
     */
60
    private $_responses = null;
61
62
    /**
63
     * Creates a new RouterErrorException.
64
     *
65
     * @param string                  $message   The Exception message to throw.
66
     * @param int                     $code      The Exception code.
67
     * @param E|null                  $previous  The previous exception used for
68
     *     the exception chaining.
69
     * @param ResponseCollection|null $responses The complete set responses
70
     *     returned by the router.
71
     */
72
    public function __construct(
73
        $message,
74
        $code = 0,
75
        E $previous = null,
76
        ResponseCollection $responses = null
77
    ) {
78
        parent::__construct($message, $code, $previous);
79
        $this->_responses = $responses;
80
    }
81
82
    /**
83
     * Gets the complete set responses returned by the router.
84
     *
85
     * @return ResponseCollection|null The complete set responses
86
     *     returned by the router.
87
     */
88
    public function getResponses()
89
    {
90
        return $this->_responses;
91
    }
92
93
    // @codeCoverageIgnoreStart
94
    // String representation is not reliable in testing
95
96
    /**
97
     * Returns a string representation of the exception.
98
     *
99
     * @return string The exception as a string.
100
     */
101
    public function __toString()
102
    {
103
        $result = parent::__toString();
104
        if ($this->_responses instanceof ResponseCollection) {
105
            $result .= "\nResponse collection:\n";
106
            ob_start();
107
            var_dump($this->_responses->toArray());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->_responses->toArray()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
108
            $result .= ob_get_clean();
109
        }
110
        return $result;
111
    }
112
113
    // @codeCoverageIgnoreEnd
114
}
115