| Conditions | 33 |
| Paths | 104 |
| Total Lines | 159 |
| Code Lines | 105 |
| Lines | 8 |
| Ratio | 5.03 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 96 | public function display_errors() { |
||
| 97 | $error_code = ''; |
||
| 98 | $trace_details = ''; |
||
| 99 | $output = BaseException::_exception_styles(); |
||
| 100 | $output .= ' |
||
| 101 | <div id="ee-error-message" class="error">'; |
||
| 102 | if ( ! WP_DEBUG ) { |
||
| 103 | $output .= ' |
||
| 104 | <p>'; |
||
| 105 | } |
||
| 106 | // cycle thru errors |
||
| 107 | foreach ( self::$_all_exceptions as $time => $ex ) { |
||
| 108 | // process trace info |
||
| 109 | if ( empty( $ex['trace'] ) ) { |
||
| 110 | $trace_details .= __( |
||
| 111 | 'Sorry, but no trace information was available for this exception.', |
||
| 112 | 'event_espresso' |
||
| 113 | ); |
||
| 114 | } else { |
||
| 115 | $trace_details .= ' |
||
| 116 | <div id="ee-trace-details"> |
||
| 117 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
||
| 118 | <tr> |
||
| 119 | <th scope="col" align="right" style="width:2.5%;">#</th> |
||
| 120 | <th scope="col" align="right" style="width:3.5%;">Line</th> |
||
| 121 | <th scope="col" align="left" style="width:40%;">File</th> |
||
| 122 | <th scope="col" align="left">' . __( 'Class', 'event_espresso' ) . '->' . __( 'Method( arguments )', 'event_espresso' ) . '</th> |
||
| 123 | </tr>'; |
||
| 124 | $last_on_stack = count( $ex['trace'] ) - 1; |
||
| 125 | // reverse array so that stack is in proper chronological order |
||
| 126 | $sorted_trace = array_reverse( $ex['trace'] ); |
||
| 127 | foreach ( $sorted_trace as $nmbr => $trace ) { |
||
| 128 | $file = isset( $trace['file'] ) ? $trace['file'] : ''; |
||
| 129 | $class = isset( $trace['class'] ) ? $trace['class'] : ''; |
||
| 130 | $type = isset( $trace['type'] ) ? $trace['type'] : ''; |
||
| 131 | $function = isset( $trace['function'] ) ? $trace['function'] : ''; |
||
| 132 | $args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : ''; |
||
| 133 | $args = isset( $trace['args'] ) && count( $trace['args'] ) > 4 ? ' <br />' . $args . '<br />' : $args; |
||
| 134 | $line = isset( $trace['line'] ) ? $trace['line'] : ''; |
||
| 135 | $zebra = $nmbr % 2 !== 0 ? ' odd' : ''; |
||
| 136 | View Code Duplication | if ( empty( $file ) && ! empty( $class ) ) { |
|
| 137 | $a = new \ReflectionClass( $class ); |
||
| 138 | $file = $a->getFileName(); |
||
| 139 | if ( empty( $line ) && ! empty( $function ) ) { |
||
| 140 | $b = new \ReflectionMethod( $class, $function ); |
||
| 141 | $line = $b->getStartLine(); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | if ( $nmbr === $last_on_stack ) { |
||
| 145 | $file = $ex['file'] !== '' ? $ex['file'] : $file; |
||
| 146 | $line = $ex['line'] !== '' ? $ex['line'] : $line; |
||
| 147 | $error_code = self::generate_error_code( $file, $trace['function'], $line ); |
||
| 148 | } |
||
| 149 | $file = \EEH_File::standardise_directory_separators( $file ); |
||
| 150 | $nmbr = ! empty( $nmbr ) ? $nmbr : ' '; |
||
| 151 | $line = ! empty( $line ) ? $line : ' '; |
||
| 152 | $file = ! empty( $file ) ? $file : ' '; |
||
| 153 | $class_display = ! empty( $class ) ? $class : ''; |
||
| 154 | $type = ! empty( $type ) ? $type : ''; |
||
| 155 | $function = ! empty( $function ) ? $function : ''; |
||
| 156 | $args = ! empty( $args ) ? '( ' . $args . ' )' : '()'; |
||
| 157 | $trace_details .= ' |
||
| 158 | <tr> |
||
| 159 | <td align="right" valign="top" class="' . $zebra . '">' . $nmbr . '</td> |
||
| 160 | <td align="right" valign="top" class="' . $zebra . '">' . $line . '</td> |
||
| 161 | <td align="left" valign="top" class="' . $zebra . '">' . $file . '</td> |
||
| 162 | <td align="left" valign="top" class="' . $zebra . '">' . $class_display . $type . $function . $args . '</td> |
||
| 163 | </tr>'; |
||
| 164 | } |
||
| 165 | $trace_details .= ' |
||
| 166 | </table> |
||
| 167 | </div>'; |
||
| 168 | } |
||
| 169 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
||
| 170 | // add generic non-identifying messages for non-privileged users |
||
| 171 | if ( ! WP_DEBUG ) { |
||
| 172 | $output .= '<span class="ee-error-user-msg-spn">' |
||
| 173 | . trim( $ex['msg'] ) |
||
| 174 | . '</span> <sup>' |
||
| 175 | . $ex['code'] |
||
| 176 | . '</sup><br />'; |
||
| 177 | } else { |
||
| 178 | // or helpful developer messages if debugging is on |
||
| 179 | $output .= ' |
||
| 180 | <div class="ee-error-dev-msg-dv"> |
||
| 181 | <p class="ee-error-dev-msg-pg"> |
||
| 182 | ' |
||
| 183 | . sprintf( |
||
| 184 | __( '%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso' ), |
||
| 185 | '<strong class="ee-error-dev-msg-str">', |
||
| 186 | $ex['name'], |
||
| 187 | '</strong> <span>', |
||
| 188 | $ex['code'] . '</span>' |
||
| 189 | ) |
||
| 190 | . '<br /> |
||
| 191 | <span class="big-text">"' |
||
| 192 | . trim( $ex['msg'] ) |
||
| 193 | . '"</span><br/> |
||
| 194 | <a id="display-ee-error-trace-' |
||
| 195 | . self::$_error_count |
||
| 196 | . $time |
||
| 197 | . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
||
| 198 | . self::$_error_count |
||
| 199 | . $time |
||
| 200 | . '"> |
||
| 201 | ' |
||
| 202 | . __( 'click to view backtrace and class/method details', 'event_espresso' ) |
||
| 203 | . ' |
||
| 204 | </a><br /> |
||
| 205 | ' |
||
| 206 | . $ex['file'] |
||
| 207 | . sprintf( |
||
| 208 | __( '%1$s( line no: %2$s )%3$s', 'event_espresso' ), |
||
| 209 | ' <span class="small-text lt-grey-text">', |
||
| 210 | $ex['line'], |
||
| 211 | '</span>' |
||
| 212 | ) |
||
| 213 | . ' |
||
| 214 | </p> |
||
| 215 | <div id="ee-error-trace-' |
||
| 216 | . self::$_error_count |
||
| 217 | . $time |
||
| 218 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
||
| 219 | ' |
||
| 220 | . $trace_details; |
||
| 221 | if ( ! empty( $class ) ) { |
||
| 222 | $output .= ' |
||
| 223 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
||
| 224 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
||
| 225 | <h3>' . __( 'Class Details', 'event_espresso' ) . '</h3>'; |
||
| 226 | $a = new \ReflectionClass( $class ); |
||
| 227 | $output .= ' |
||
| 228 | <pre>' . $a . '</pre> |
||
| 229 | </div> |
||
| 230 | </div>'; |
||
| 231 | } |
||
| 232 | $output .= ' |
||
| 233 | </div> |
||
| 234 | </div> |
||
| 235 | <br />'; |
||
| 236 | } |
||
| 237 | $this->write_to_error_log( $time, $ex ); |
||
| 238 | } |
||
| 239 | // remove last linebreak |
||
| 240 | $output = substr( $output, 0, count( $output ) - 7 ); |
||
| 241 | if ( ! WP_DEBUG ) { |
||
| 242 | $output .= ' |
||
| 243 | </p>'; |
||
| 244 | } |
||
| 245 | $output .= ' |
||
| 246 | </div>'; |
||
| 247 | $output .= self::_print_scripts( true ); |
||
| 248 | if ( defined( 'DOING_AJAX' ) ) { |
||
| 249 | echo json_encode( array( 'error' => $output ) ); |
||
| 250 | exit(); |
||
| 251 | } |
||
| 252 | echo $output; |
||
| 253 | die(); |
||
| 254 | } |
||
| 255 | |||
| 504 | // Location: /core/exceptions/BaseException.php |
This check marks private properties in classes that are never used. Those properties can be removed.