This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace nyx\diagnostics\debug; |
||
2 | |||
3 | // Internal dependencies |
||
4 | use nyx\diagnostics; |
||
5 | |||
6 | /** |
||
7 | * Exception Inspector |
||
8 | * |
||
9 | * The Exception being inspected and the (optional) Handler are immutable. It you do not set the Handler during |
||
10 | * construction of the Inspector it will not be set for the whole lifecycle of the Inspector. |
||
11 | * |
||
12 | * @package Nyx\Diagnostics\Debug |
||
13 | * @version 0.0.7 |
||
14 | * @author Michal Chojnacki <[email protected]> |
||
15 | * @copyright 2012-2016 Nyx Dev Team |
||
16 | * @link http://docs.muyo.io/nyx/diagnostics/debug.html |
||
17 | * @todo Handle previous exceptions (instantiate Inspectors for them on the fly while creating the Trace?). |
||
18 | */ |
||
19 | class Inspector |
||
20 | { |
||
21 | /** |
||
22 | * @var \Exception The Exception that is to be inspected. |
||
23 | */ |
||
24 | private $exception; |
||
25 | |||
26 | /** |
||
27 | * @var Trace A Trace instance. |
||
28 | */ |
||
29 | private $trace; |
||
30 | |||
31 | /** |
||
32 | * @var handlers\Exception The Exception Handler currently handling the inspected Exception. |
||
33 | */ |
||
34 | private $handler; |
||
35 | |||
36 | /** |
||
37 | * Prepares a new Inspector by feeding him with an Exception that shall be inspected and the Handler which |
||
38 | * started the inspection. |
||
39 | * |
||
40 | * @param \Exception $exception The Exception that is to be inspected. |
||
41 | * @param handlers\Exception $handler The Handler which started the inspection, if available. |
||
42 | */ |
||
43 | public function __construct(\Exception $exception, handlers\Exception $handler = null) |
||
44 | { |
||
45 | $this->exception = $exception; |
||
46 | $this->handler = $handler; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns the Exception currently being inspected. |
||
51 | * |
||
52 | * @return \Exception The Exception being inspected. |
||
53 | */ |
||
54 | public function getException() : \Exception |
||
55 | { |
||
56 | return $this->exception; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Returns the Exception Handler currently handling the inspected Exception, if available. |
||
61 | * |
||
62 | * @return handlers\Exception|null |
||
63 | */ |
||
64 | public function getHandler() |
||
65 | { |
||
66 | return $this->handler; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Returns a Trace instance representing the stack trace of the inspected Exception. |
||
71 | * |
||
72 | * If the trace contains a handlers\Error entry (indicating the Exception is the result of an internal |
||
73 | * error -> exception conversion), that frame will be removed. If it does not, a frame for the actual Exception |
||
74 | * will be prepended to the frame stack instead to make it easier to iterate over the causality chain. |
||
75 | * |
||
76 | * @return Trace |
||
77 | */ |
||
78 | public function getTrace() : Trace |
||
79 | { |
||
80 | // No need for further magic if we've already instantiated a Trace Sequence. |
||
81 | if ($this->trace !== null) { |
||
82 | return $this->trace; |
||
83 | } |
||
84 | |||
85 | // The frames might differ from the actual trace after we are done. See below. |
||
86 | $frames = $this->getFrames(); |
||
87 | |||
88 | // Make sure the first frame in the trace actually points to the Exception we're inspecting. |
||
89 | if (empty($frames[0]['line'])) { |
||
90 | $frames[0] = array_merge(diagnostics\Debug::exceptionToArray($this->exception), $frames[0]); |
||
91 | } else { |
||
92 | array_unshift($frames, diagnostics\Debug::exceptionToArray($this->exception)); |
||
93 | } |
||
94 | |||
95 | // Instantiate a new Trace Sequence and cache it locally. |
||
96 | return $this->trace = new Trace($frames); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Returns the traced frames from the inspected Exception. |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | protected function getFrames() : array |
||
105 | { |
||
106 | $frames = $this->exception->getTrace(); |
||
107 | |||
108 | if (!$this->exception instanceof \ErrorException) { |
||
0 ignored issues
–
show
|
|||
109 | return $frames; |
||
110 | } |
||
111 | |||
112 | // We're going to determine if the exception in fact stems from an irrecoverable fatal error. |
||
113 | $fatal = false; |
||
114 | |||
115 | // Note: E_RECOVERABLE_ERROR and E_PARSE should as of PHP7 be entirely converted to Throwables |
||
116 | // so they should be caught by an Exception Handler directly instead of first going through an Error Handler |
||
117 | // and being converted to an Error Exception, let alone a FatalError Exception. We still keep |
||
118 | // them here for edge cases, however. |
||
119 | switch ($this->exception->getSeverity()) { |
||
120 | case E_ERROR: |
||
121 | case E_CORE_ERROR: |
||
122 | case E_COMPILE_ERROR: |
||
123 | case E_USER_ERROR: |
||
124 | case E_RECOVERABLE_ERROR: |
||
125 | case E_PARSE: |
||
126 | $fatal = true; |
||
127 | break; |
||
128 | } |
||
129 | |||
130 | // Without XDebug we don't actually have any means to determine the stacktrace of a fatal error. |
||
131 | if (!$fatal || !extension_loaded('xdebug') || !xdebug_is_enabled()) { |
||
132 | |||
133 | // Remove our (error) handler from the stack trace (it's otherwise always going to occlude |
||
134 | // the actual exception). |
||
135 | array_shift($frames); |
||
136 | |||
137 | return $frames; |
||
138 | } |
||
139 | |||
140 | // Remove our internal handling logic from the stack trace so it doesn't occlude the actual trace. |
||
141 | $frames = array_diff_key(array_reverse(xdebug_get_function_stack()), debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); |
||
142 | |||
143 | // Handle some potential inconsistencies between XDebug and the way we want handle things. |
||
144 | foreach ($frames as &$frame) { |
||
145 | |||
146 | if ('dynamic' === $frame['type']) { |
||
147 | $frame['type'] = '->'; |
||
148 | } elseif ('static' === $frame['type']) { |
||
149 | $frame['type'] = '::'; |
||
150 | } |
||
151 | |||
152 | // XDebug uses a different key for the args array. |
||
153 | if (isset($frame['params']) && !isset($frame['args'])) { |
||
154 | $frame['args'] = $frame['params']; |
||
155 | unset($frame['params']); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | return $frames; |
||
160 | } |
||
161 | } |
||
162 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.