Errorhandler   C
last analyzed

Complexity

Total Complexity 71

Size/Duplication

Total Lines 664
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 664
rs 5.2299
c 1
b 0
f 0
wmc 71
lcom 1
cbo 3

14 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 1
A handleErrorAsErrorException() 0 4 1
B getClassProperties() 0 27 5
A getGithubIssueURL() 0 16 1
D handleError() 0 101 16
B getTemplateEditorLink() 0 24 5
F getDebugBacktrace() 0 148 16
C formatBacktraceArgument() 0 59 14
A getErrorContext() 0 56 3
A getSupportBacklinks() 0 16 1
A getFileLink() 0 15 2
A getBugtrackerBacklinks() 0 21 1
A getTracNewTicketURL() 0 23 2
A catchFatalErrors() 0 23 3

How to fix   Complexity   

Complex Class

Complex classes like Errorhandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Errorhandler, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Koch Framework
5
 * Jens-André Koch © 2005 - onwards.
6
 *
7
 * This file is part of "Koch Framework".
8
 *
9
 * License: GNU/GPL v2 or any later version, see LICENSE file.
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace Koch\Exception;
26
27
use Koch\Exception\Renderer\SmartyTemplateError;
28
use Koch\Exception\Renderer\YellowScreenOfDeath;
29
30
/**
31
 * Koch Framework - Class for Errorhandling.
32
 *
33
 * Sets up a custom Errorhandler.
34
 *
35
 * @example
36
 * <code>
37
 * 1) trigger_error('Errormessage', E_ERROR_TYPE);
38
 *    E_ERROR_TYPE as string or int
39
 * 2) trigger_error('Errorhandler Test - This should trigger a E_USER_NOTICE!', E_USER_NOTICE);
40
 * </code>
41
 */
42
class Errorhandler
43
{
44
    /**
45
     * Registers this class as the new PHP errorhandler, thereby overwriting any previous handlers.
46
     */
47
    public static function register()
48
    {
49
        set_error_handler(['Errorhandler', 'handleError']);
50
        //set_error_handler(array('Errorhandler', 'handleErrorAsErrorException'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
        //set_exception_handler(array('Errorhandler', 'handleException'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
        //register_shutdown_function(array('Errorhandler, 'catchFatalErrors'));
53
    }
54
55
    /**
56
     * Handle Error as ErrorException.
57
     *
58
     * @param int    $errnum   contains the error as integer.
59
     * @param string $message  contains the error string.
60
     * @param string $filename contains the filename with occuring error.
61
     * @param int    $lineno   contains the line of error.
62
     *
63
     * @throws \ErrorException
64
     */
65
    public function handleErrorAsErrorException($errnum, $message, $filename, $lineno)
0 ignored issues
show
Unused Code introduced by
The parameter $errnum is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        throw new \ErrorException($message, 0, $severity, $filename, $lineno);
68
    }
69
70
    /**
71
     * Koch Framework - Error callback.
72
     *
73
     * This is basically a switch statement, defining the actions taken,
74
     * in case of serveral PHP error states.
75
     *
76
     * @link http://www.usegroup.de/software/phptutorial/debugging.html
77
     * @link http://www.php.net/manual/de/function.set-error-handler.php
78
     * @link http://www.php.net/manual/de/errorfunc.constants.php
79
     *
80
     * @param int    $errnum     contains the error as integer.
81
     * @param string $errstr     contains the error string.
82
     * @param string $errfile    contains the filename with occuring error.
83
     * @param string $errline    contains the line of error.
84
     * @param string $errcontext (optional) array with variables from error context.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $errcontext not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
85
     */
86
    public static function handleError($errnum, $errstr, $errfile, $errline, $errcontext = null)
87
    {
88
        // return, if the error is suppressed, due to (@)silencing-operator
89
        if (error_reporting() === 0) {
90
            return;
91
        }
92
93
        /*
94
         * Assemble the error informations
95
         */
96
97
        /*
98
         * Definition of PHP error types, with names for all the php error codes.
99
         * @link http://php.net/manual/de/errorfunc.constants.php
100
         */
101
        $errorTypes = [
102
            1     => 'E_ERROR',              // fatal run-time errors, like php is failing memory allocation
103
            2     => 'E_WARNING',            // Run-time warnings (non-fatal errors)
104
            4     => 'E_PARSE',              // compile-time parse errors - generated by the parser
105
            8     => 'E_NOTICE',             // Run-time notices (could be an indicator for an error)
106
            16    => 'E_CORE_ERROR',         // PHP Core reports errors in PHP's initial startup
107
            32    => 'E_CORE_WARNING',       // PHP Core reports warning (non-fatal errors)
108
            64    => 'E_COMPILE_ERROR',      // Zend Script Engine reports fatal compile-time errors
109
            128   => 'E_COMPILE_WARNING',    // Zend Script Engine reports compile-time warnings (non-fatal errors)
110
            256   => 'E_USER_ERROR',         // trigger_error(), user_error() reports user-defined error
111
            512   => 'E_USER_WARNING',       // trigger_error(), user_error() reports user-defined warning
112
            1024  => 'E_USER_NOTICE',        // trigger_error(), user_error() reports user-defined notice
113
            2048  => 'E_STRICT',             // PHP suggests codechanges to ensure interoperability / forwad compat
114
            4096  => 'E_RECOVERABLE_ERROR',  // catchable fatal error, if not catched it's an e_error (since PHP 5.2.0)
115
            8191  => 'E_ALL 8191',           // PHP 6 -> 8191
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
116
            8192  => 'E_DEPRECATED',         // notice marker for 'in future' deprecated php-functions (since PHP 5.3.0)
117
            16384 => 'E_USER_DEPRECATED',    // trigger_error(), user_error() reports user-defined deprecated functions
118
            30719 => 'E_ALL 30719 PHP5.3.x', // all errors and warnings - E_ALL of PHP Version 5.3.x
119
            32767 => 'E_ALL 32767 PHP6',      // all errors and warnings - E_ALL of PHP Version 6
120
        ];
121
122
        // get the errorname from the array via $errornumber
123
        $errorname = isset($errorTypes[$errnum]) ? $errorTypes[$errnum] : '';
124
125
        // Handling the ErrorType via Switch
126
        switch ($errorname) {
127
            // This one is handled by register_shutdown_function + catchFatalErrorsShutdownHandler
128
            case 'E_ERROR':
129
                $errorname .= ' [PHP Fatal Error]';
130
                break;
131
            // What are the errortypes that can be handled by a user-defined errorhandler?
132
            case 'E_WARNING':
133
                $errorname .= ' [PHP Warning]';
134
                break;
135
            case 'E_NOTICE':
136
                $errorname .= ' [PHP Notice]';
137
                break;
138
            case 'E_USER_ERROR':
139
                $errorname .= ' [Koch Framework Internal Error]';
140
                break;
141
            case 'E_USER_WARNING':
142
                $errorname .= ' [Koch Framework Internal Error]';
143
                break;
144
            case 'E_USER_NOTICE':
145
                $errorname .= ' [Koch Framework Internal Error]';
146
                break;
147
            case 'E_ALL':
148
            case 'E_STRICT':
149
                $errorname .= ' [PHP Strict]';
150
                break;
151
            case 'E_RECOVERABLE_ERROR':
152
                $errorname .= ' [php not-unstable]';
153
                break;
154
            // when it's not in there, its an unknown errorcode
155
            default:
156
                $errorname .= ' Unknown Errorcode [' . $errnum . ']: ';
157
        }
158
159
        // make the errorstring more useful by linking it to the php manual
160
        $pattern     = "/<a href='(.*)'>(.*)<\/a>/";
161
        $replacement = '<a href="http://php.net/$1" target="_blank">?</a>';
162
        $errstr      = preg_replace($pattern, $replacement, $errstr);
163
164
        // if DEBUG is set, display the error
165
        if (defined('DEBUG') and DEBUG === 1) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
166
167
            /*
168
             * SMARTY ERRORS are thrown by trigger_error() - so they bubble up as E_USER_ERROR.
169
             *
170
             * In order to handle smarty errors with an seperated error display,
171
             * we need to detect, if an E_USER_ERROR is either incoming from
172
             * SMARTY or from a template_c file (extension tpl.php).
173
             */
174
            if ((true === (bool) mb_strpos(mb_strtolower($errfile), 'smarty')) or
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
175
                (true === (bool) mb_strpos(mb_strtolower($errfile), 'tpl.php'))) {
176
                // render the smarty template error
177
                echo SmartyTemplateError::render($errnum, $errorname, $errstr, $errfile, $errline, $errcontext);
178
            } else {
179
                // render normal error display, with all pieces of information, except backtraces
180
                echo YellowScreenOfDeath::renderError($errnum, $errorname, $errstr, $errfile, $errline, $errcontext);
181
            }
182
        }
183
184
        // Skip PHP internal error handler
185
        return true;
186
    }
187
188
    /**
189
     * getTemplateEditorLink.
190
     *
191
     * a) determines the path to the invalid template file
192
     * b) provides the html-link to the templateeditor for this file
193
     *
194
     * @param string      $errfile    Template File with the Error.
195
     * @param string      $errline    Line Number of the Error.
196
     * @param string|null $errcontext
197
     *
198
     * @todo correct link to the templateeditor
199
     */
200
    public static function getTemplateEditorLink($errfile, $errline, $errcontext)
201
    {
202
        // display the link to the templateeditor, if we are in DEVELOPMENT MODE
203
        // and more essential if the error relates to a template file
204
        if (defined('DEVELOPMENT') and DEVELOPMENT === 1 && (mb_strpos(mb_strtolower($errfile), '.tpl'))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
205
            // ok, it's a template, so we have a template context to determine the templatename
206
            $tpl_vars = $errcontext['this']->getTemplateVars();
0 ignored issues
show
Coding Style introduced by
$tpl_vars does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
207
208
            // maybe the templatename is defined in tpl_vars
209
            if ($tpl_vars['templatename'] !== null) {
0 ignored issues
show
Coding Style introduced by
$tpl_vars does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
210
                $errfile = $tpl_vars['templatename'];
0 ignored issues
show
Coding Style introduced by
$tpl_vars does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
211
            } else { // else use resource_name from the errorcontext
212
                $errfile = $errcontext['resource_name'];
213
            }
214
215
            // construct the link to the tpl-editor
216
            $html = '<br/><a href="index.php?mod=templatemanager&amp;sub=admin&amp;action=editor';
217
            $html .= '&amp;file=' . $errfile . '&amp;line=' . $errline;
218
            $html .= '">Edit the Template</a>';
219
220
            // return the link
221
            return $html;
222
        }
223
    }
224
225
    /**
226
     * getDebugBacktrace.
227
     *
228
     * Transforms the output of php's debug_backtrace() and exception backtraces
229
     * to a more readable html format.
230
     *
231
     * @return string $backtrace_string contains the backtrace
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
232
     */
233
    public static function getDebugBacktrace($trace = null)
234
    {
235
        // show backtraces only in DEBUG mode
236
        if (defined('DEBUG') === false xor DEBUG === 0) {
237
            return;
238
        }
239
240
        // Normally backtraces are incomming from exceptions.
241
        // But, when called from the errorhandler, we need to fetch the traces ourselfs.
242
        if ($trace === null) {
243
            if (function_exists('xdebug_get_function_stack')) {
244
                $trace = xdebug_get_function_stack();
245
            } else {
246
                $trace = debug_backtrace();
247
            }
248
249
            /*
250
             * Now we get rid of several last calls in the backtrace stack,
251
             * to get nearer to the relevant error position in the stack.
252
             *
253
             * What exactly happens is: we shift-off the last 3 calls to
254
             * 1) getDebugBacktrace()   [this method itself]
255
             * 2) yellowScreenOfDeath() [our exception and error display method]
256
             * 3) trigger_error()       [php core function call]
257
             */
258
            $trace = array_slice($trace, 3);
259
        }
260
261
        /*
262
         * Assemble the html for the backtrace panel
263
         */
264
        $html = '';
265
        $html .= '<div id="panel3" class="panel"><h3>Backtrace</h3>';
266
        $html .= '<table class="cs-backtrace-table" width="95%">';
267
268
        // table row 1 - header
269
        $html .= '<tr><th width="2%">Callstack</th><th>Function</th><th width="46%">Location</th></tr>';
270
271
        // the number of backtraces
272
        $backtraces_counter_i = count($trace) - 1;
0 ignored issues
show
Coding Style introduced by
$backtraces_counter_i does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
273
274
        for ($i = 0; $i <= $backtraces_counter_i; ++$i) {
0 ignored issues
show
Coding Style introduced by
$backtraces_counter_i does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
275
            $html .= '<tr>';
276
277
            // Position in the Callstack
278
            $html .= '<td align="center">' . (($backtraces_counter_i - $i) + 1) . '</td>';
0 ignored issues
show
Coding Style introduced by
$backtraces_counter_i does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
279
280
            if (isset($trace[$i]['class']) === false) {
281
                $html .= '<td>[A PHP Core Function Call]</td>';
282
            } else {
283
284
                // replace trace type string with it's operator
285
                if ($trace[$i]['type'] === 'dynamic') {
286
                    $trace[$i]['type'] = '->';
287
                } else {
288
                    $trace[$i]['type'] = '::';
289
                }
290
291
                $html .= '<td>';
292
293
                // show the function call, e.g. Class->Method() or Class::Method()
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
294
                $html .= $trace[$i]['class'] . $trace[$i]['type'] . $trace[$i]['function'] . '()';
295
296
                // if the class is one of our own, add backlink to API Documentation
297
                if (1 === preg_match('/^Koch/', $trace[$i]['class'])) {
298
                    $html .= '<span class="error-class">';
299
                    $html .= '<a target="_new" href="http://docs.kf.com/en/latest/api/';
300
                    $html .= str_replace('\\', '_', $trace[$i]['class']);
301
                    $html .= '.html"> ' . $trace[$i]['class'] . '</a></span>';
302
                } else {
303
                    // else it's a php internal class, then add a backlink to the php manual
304
                    $classReflection = new \ReflectionClass($trace[$i]['class']);
305
                    if ($classReflection->isInternal()) {
306
                        $html .= '<span class="error-class"><a target="_new" href="http://php.net/manual/en/class.';
307
                        $html .= str_replace('_', '-', strtolower($trace[$i]['class']));
308
                        $html .= '.php">' . $trace[$i]['class'] . '</a></span>';
309
                    } else {
310
                        $html .= '<span class="error-class">' . $trace[$i]['class'] . '</span>';
311
                    }
312
                }
313
314
                // is this a normal php function? if yes, add a backlink to the php manual
315
                if (function_exists($trace[$i]['function'])) {
316
                    $functionReflection = new \ReflectionFunction($trace[$i]['function']);
317
                    if ($functionReflection->isInternal()) {
318
                        $html .= '<span class="error-function">';
319
                        $html .= '<a target="_new" href="http://php.net/manual/en/function.';
320
                        $html .= str_replace('_', '-', $trace[$i]['function']);
321
                        $html .= '.php">' . $trace[$i]['function'] . '</a></span>';
322
                    }
323
                }
324
325
                // XDebug uses the array key 'params' for the method parameters array
326
                // PHP backtrace uses 'args', so let's rename to 'args'
327
                if (isset($trace[$i]['params'])) {
328
                    $trace[$i]['args'] = $trace[$i]['params'];
329
                    unset($trace[$i]['params']);
330
                }
331
332
                // Method Arguments
333
                if (isset($trace[$i]['args']) && empty($trace[$i]['args']) === false) {
334
                    // the number of arguments (method parameters)
335
                    $backtrace_counter_j = count($trace[$i]['args']) - 1;
0 ignored issues
show
Coding Style introduced by
$backtrace_counter_j does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
336
337
                    // use reflection to get the method parameters (and their names for display)
338
                    $reflected_method = new \ReflectionMethod($trace[$i]['class'], $trace[$i]['function']);
0 ignored issues
show
Coding Style introduced by
$reflected_method does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
339
                    /* @var $reflected_params \ReflectionParameter */
340
                    $reflected_params = $reflected_method->getParameters();
0 ignored issues
show
Coding Style introduced by
$reflected_params does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
341
342
                    // render a table with method parameters
343
                    // argument position | name | type | value
344
                    $html .= '<table style="border-collapse: collapse;">';
345
                    $html .= '<tr><th style="line-height: 0.8em;" colspan="4">Parameters</th></tr>';
346
                    $html .= '<tr style="line-height: 0.8em;">';
347
                    $html .= '<th>Pos</th><th>Name = Default Value</th><th>Type</th><th>Value</th></tr>';
348
349
                    // loop over all arguments
350
                    for ($j = 0; $j <= $backtrace_counter_j; ++$j) {
0 ignored issues
show
Coding Style introduced by
$backtrace_counter_j does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
351
                        // fetch data for this argument
352
                        $data = self::formatBacktraceArgument($trace[$i]['args'][$j]);
353
                        // fetch current reflection parameter object
354
                        $parameter = $reflected_params[$j];
0 ignored issues
show
Coding Style introduced by
$reflected_params does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
355
                        // get just the parameter name and it's default value
356
                        preg_match('/\[ ([^[]+) \]/', $parameter, $matches);
357
358
                        $html .= '<tr>';
359
                        $html .= '<td>' . ($j + 1) . '</td>'; // pos
360
                        $html .= '<td>' . $matches['1'] . '</td>'; // name
361
                        $html .= '<td>' . $data['type'] . '</td>'; // type
362
                        $html .= '<td>' . $data['arg'] . '</td>'; // value $defaultValue
363
                    }
364
                    $html .= '</tr></table>';
365
                }
366
                $html .= '</td>';
367
            }
368
369
            // Location with Link
370
            if (isset($trace[$i]['file'])) {
371
                $html .= '<td>' . self::getFileLink($trace[$i]['file'], $trace[$i]['line']) . '</td>';
372
            }
373
374
            $html .= '</tr>';
375
        }
376
377
        $html .= '</table></div>';
378
379
        return $html;
380
    }
381
382
    /**
383
     * formatBacktraceArgument.
384
     *
385
     * Performs a type check on the backtrace argument and beautifies it.
386
     *
387
     * This formater is based on comments for debug-backtrace in the php manual
388
     *
389
     * @link http://de2.php.net/manual/en/function.debug-backtrace.php#30296
390
     * @link http://de2.php.net/manual/en/function.debug-backtrace.php#47644
391
     *
392
     * @param backtraceArgument mixed The argument for type identification and string formatting.
393
     *
394
     * @return array With keys 'arg' and 'type'.
395
     */
396
    public static function formatBacktraceArgument($argument)
397
    {
398
        // do not throw a notice on PHP 5.3 - the constant was added with PHP 5.4 htmlspecialchars()
399
        defined('ENT_SUBSTITUTE') || define('ENT_SUBSTITUTE', 8);
400
401
        $result = [];
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
402
        $arg    = '';
403
        $type   = '';
404
405
        switch (gettype($argument)) {
406
            case 'boolean':
407
                $type .= '<span>bool</span>';
408
                $arg .= $argument ? 'true' : 'false';
409
                break;
410
            case 'integer':
411
                $type .= '<span>int</span>';
412
                $arg .= $argument;
413
                break;
414
            case 'float':
415
            case 'double':
416
                $type .= '<span>float/double</span>';
417
                $arg .= $argument;
418
                break;
419
            case 'string':
420
                $type .= '<span>string</span>';
421
                $argument = htmlspecialchars($argument, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
422
                $arg .= \Koch\Functions\Functions::shortenString($argument);
423
                break;
424
            case 'array':
425
                $type .= '<span>array</span>';
426
                $arg .= count($argument);
427
                break;
428
            case 'object':
429
                $type .= '<span>object</span>';
430
                $arg .= get_class($argument);
431
                /* @todo use self::getClassProperties($backtraceArgument) */
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
432
                break;
433
            case 'resource':
434
                $type .= '<span>resource</span>';
435
                if ($type === 'stream') {
436
                    $type .= '(stream)';
437
                    $meta = stream_get_meta_data($argument);
438
                    if (isset($meta['uri'])) {
439
                        $type .= htmlspecialchars($meta['uri'], ENT_NOQUOTES, 'UTF-8');
440
                    }
441
                }
442
                $arg .= mb_strstr($argument, '#') . ' - ' . get_resource_type($argument);
443
                break;
444
            case 'NULL':
445
                $type .= '<span>null</span>';
446
                $arg .= '';
447
                break;
448
            default:
449
                $type .= 'Unknown';
450
                $arg .= 'Unknown';
451
        }
452
453
        return compact('arg', 'type');
454
    }
455
456
    public static function getClassProperties($class, $nestingLevel = 2)
457
    {
458
        $html = '';
459
        $html .= '<ul>';
460
        $ref = new ReflectionClass($class);
461
        foreach ($ref->getProperties() as $p) {
462
            $html .= '<li><span>';
463
            // static ?
464
            $html .= ($p->isStatic()) ? '<em>static</em> ' : '';
465
            // scope ?
466
            if ($p->isPrivate()) {
467
                $html .= 'private';
468
                $p->setAccessible(true);
469
            } elseif ($p->isProtected()) {
470
                $html .= 'protected';
471
                $p->setAccessible(true);
472
            } else {
473
                $html .= 'public';
474
            }
475
            $html .= ' </span><span>$' . $p->getName() . ' </span>';
476
            $html .= '<span>' . self::formatBacktraceArgument($p->getValue($class), $nestingLevel - 1) . '</span>';
0 ignored issues
show
Unused Code introduced by
The call to Errorhandler::formatBacktraceArgument() has too many arguments starting with $nestingLevel - 1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
477
            $html .= '</li>';
478
        }
479
        $html .= '</ul>';
480
481
        return $html;
482
    }
483
484
    /**
485
     * getErrorContext displayes some additional lines of sourcecode around the line with error.
486
     *
487
     * @param string $file  file with the error in it
488
     * @param int    $scope the context scope (defining how many lines surrounding the error are displayed)
489
     * @param int    $line  the line with the error in it
490
     *
491
     * @return string sourcecode of file
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
492
     */
493
    public static function getErrorContext($file, $line, $scope)
494
    {
495
        // ensure that sourcefile is readable
496
        if (true === is_readable($file)) {
497
            // Scope Calculations
498
            $surround_lines             = round($scope / 2);
0 ignored issues
show
Coding Style introduced by
$surround_lines does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
499
            $errorcontext_starting_line = $line - $surround_lines;
0 ignored issues
show
Coding Style introduced by
$errorcontext_starting_line does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
500
            $errorcontext_ending_line   = $line + $surround_lines;
0 ignored issues
show
Coding Style introduced by
$errorcontext_ending_line does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
501
502
            // create linenumbers array
503
            $lines_array = range($errorcontext_starting_line, $errorcontext_ending_line);
0 ignored issues
show
Coding Style introduced by
$lines_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
504
505
            // colourize the errorous linenumber red
506
            $lines_array[$surround_lines] = '<span class="error-line">' . $lines_array[$surround_lines] . '</span>';
0 ignored issues
show
Coding Style introduced by
$lines_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
507
            $lines_array[$surround_lines] .= '<span class="error-triangle">&#9654;</span>';
0 ignored issues
show
Coding Style introduced by
$lines_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
508
509
            // transform linenumbers array to string for later display, use spaces as separator
510
            $lines_html = implode($lines_array, ' ');
0 ignored issues
show
Coding Style introduced by
$lines_html does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
511
512
            // get ALL LINES syntax highlighted source-code of the file and explode it into an array
513
            // the if check is needed to workaround "highlight_file() has been disabled for security reasons"
514
            if (function_exists('highlight_file')) {
515
                $array_content = explode('<br />', highlight_file($file, true));
0 ignored issues
show
Coding Style introduced by
$array_content does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
516
            } else {
517
                $array_content = explode('<br />', $file);
0 ignored issues
show
Coding Style introduced by
$array_content does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
518
            }
519
520
            // get the ERROR SURROUNDING LINES from ALL LINES
521
            $array_content_sliced = array_slice($array_content, $errorcontext_starting_line - 1, $scope, true);
0 ignored issues
show
Coding Style introduced by
$array_content_sliced does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
522
523
            $result = array_values($array_content_sliced);
0 ignored issues
show
Coding Style introduced by
$array_content_sliced does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
524
525
            // @todo now colourize the background of the errorous line RED
526
            //$result[$surround_lines] = '<span style="background-color:#BF0000;">'
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
527
            // . $result[$surround_lines] .'</span>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
528
529
            // @todo remove 4 space identation, still buggy on inline stmts
530
            //foreach ($result as $i => $line) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
531
            //     $result[$i] = str_replace('&nbsp;&nbsp;&nbsp;&nbsp;', '', $line);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
532
            //}
533
534
            // transform the array into html string
535
            // enhance readablility by imploding the array with spaces (try either ' ' or  '<br>')
536
            $errorcontext_lines = implode($result, '<br>');
0 ignored issues
show
Coding Style introduced by
$errorcontext_lines does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
537
538
            $sprintf_html = '<table>
0 ignored issues
show
Coding Style introduced by
$sprintf_html does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
539
                                <tr>
540
                                    <td class="num">' . CR . '%s' . CR . '</td>
541
                                    <td><pre>' . CR . '%s' . CR . '</pre></td>
542
                                </tr>
543
                            </table>';
544
545
            // @todo consider using wordwrap() to limit too long source code lines?
546
            return sprintf($sprintf_html, $lines_html, $errorcontext_lines);
0 ignored issues
show
Coding Style introduced by
$sprintf_html does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
547
        }
548
    }
549
550
    /**
551
     * Returns the Clansuite Support Backlinks as HTML string.
552
     *
553
     * @return string Clansuite Support Backlinks as HTML.
554
     */
555
    public static function getSupportBacklinks()
556
    {
557
        $html = '<div id="support-backlinks" style="padding-top: 45px; float:right;">';
558
        $html  .= '<!-- Live Support JavaScript -->
559
                   <a class="btn" href="http://support.clansuite.com/chat.php"';
560
        $html  .= ' target="_blank">Contact Support (Start Chat)</a>
561
                   <!-- Live Support JavaScript -->';
562
        $html  .= '<a class="btn" href="http://trac.clansuite.com/newticket/">Bug-Report</a>
563
                   <a class="btn" href="http://forum.clansuite.com/">Support-Forum</a>
564
                   <a class="btn" href="http://docs.clansuite.com/">Manuals</a>
565
                   <a class="btn" href="http://clansuite.com/">visit clansuite.com</a>
566
                   <a class="btn" href="#top"> &#9650; Top </a>
567
                   </div>';
568
569
        return $html;
570
    }
571
572
    /**
573
     * Returns a link to the file:line with the error.
574
     *
575
     * a) This uses the file "xdebug.file_link_format" php.ini configuration directive,
576
     *    which defines a link template for calling your Editor/IDE with file and line.
577
     * b) returns NO link, just file:line.
578
     *
579
     * @return string Link to file and line with error.
580
     */
581
    public static function getFileLink($file, $line)
582
    {
583
        $file = str_replace(APPLICATION_PATH, '..' . DIRECTORY_SEPARATOR, $file);
584
585
        // a
586
        $fileLinkFormatString = ini_get('xdebug.file_link_format');
587
        if (isset($fileLinkFormatString)) {
588
            $link = strtr($fileLinkFormatString, ['%f' => $file, '%l' => $line]);
589
590
            return sprintf(' in <a href="%s" title="Edit file">%s line #%d</a>', $link, $file, $line);
591
        }
592
593
        // b
594
        return sprintf(' in %s line #%d', $file, $line);
595
    }
596
597
    /**
598
     * Adds a link to our bugtracker, for creating a new ticket with the errormessage.
599
     *
600
     * @param string $errorstring the errormessage
601
     *
602
     * @return string html-representation of the bugtracker links
603
     */
604
    public static function getBugtrackerBacklinks($errorstring, $errorfile, $errorline, $errorcontext)
0 ignored issues
show
Unused Code introduced by
The parameter $errorcontext is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
605
    {
606
        $msg1 = '<div id="panel5" class="panel"><h3>' . 'Found a bug in Clansuite?' . '</h3><p>';
607
        $msg2 = 'If you think this should work and you can reproduce the problem,';
608
        $msg2 .= ' please consider creating a bug report.';
609
        $msg3 = 'Before creating a new bug report, please first try searching for similar issues,';
610
        $msg3 .= ' as it is quite likely that this problem has been reported before.';
611
        $msg4 = 'Otherwise, please create a new bug report describing the problem and explain how to reproduce it.';
612
613
        $search_link = NL . NL . '<a class="btn" target="_blank" href="http://trac.clansuite.com/search?q=';
0 ignored issues
show
Coding Style introduced by
$search_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
614
        $search_link .= htmlentities($errorstring, ENT_QUOTES) . '&noquickjump=1&ticket=on">';
0 ignored issues
show
Coding Style introduced by
$search_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
615
        $search_link .= '&#9658; Search for similar issue';
0 ignored issues
show
Coding Style introduced by
$search_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
616
        $search_link .= '</a>';
0 ignored issues
show
Coding Style introduced by
$search_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
617
618
        $newticket_link = '&nbsp;<a class="btn" target="_blank" href="';
0 ignored issues
show
Coding Style introduced by
$newticket_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
619
        $newticket_link .= self::getTracNewTicketURL($errorstring, $errorfile, $errorline) . '">';
0 ignored issues
show
Coding Style introduced by
$newticket_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
620
        $newticket_link .= '&#9658; Create new ticket';
0 ignored issues
show
Coding Style introduced by
$newticket_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
621
        $newticket_link .= '</a>';
0 ignored issues
show
Coding Style introduced by
$newticket_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
622
623
        return $msg1 . $msg2 . NL . $msg3 . NL . $msg4 . $search_link . $newticket_link . '</p></div>' . NL;
0 ignored issues
show
Coding Style introduced by
$search_link does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
624
    }
625
626
    /**
627
     * Returns a link to Trac's New Ticket Dialog prefilled with error data.
628
     *
629
     * @returns string Link to Trac's Create New Ticket Dialog prefilled.
630
     *
631
     * @param string $summary
632
     */
633
    public static function getTracNewTicketURL($summary, $errorfile, $errorline)
0 ignored issues
show
Coding Style introduced by
getTracNewTicketURL uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
634
    {
635
        /*
636
         * This is the error description.
637
         * It's written in trac wiki formating style.
638
         *
639
         * @link http://trac.clansuite.com/wiki/WikiFormatting
640
         */
641
        $description = '[Error] ' . $summary . ' [[BR]] [File] ' . $errorfile . ' [[BR]] [Line] ' . $errorline;
642
643
        // options array for http_build_query
644
        $array = [
645
            'summary'     => $summary,
646
            'description' => $description,
647
            'type'        => 'defect-bug',
648
            'milestone'   => 'Triage-Neuzuteilung',
649
            'version'     => APPLICATION_VERSION,
650
            #'component'   => '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
651
            'author' => isset($_SESSION['user']['email']) ? $_SESSION['user']['email'] : '',
652
        ];
653
654
        return 'http://trac.clansuite.com/newticket/?' . http_build_query($array);
655
    }
656
657
    /**
658
     * Returns a link to a new Issue on Github.
659
     *
660
     * @link http://developer.github.com/v3/issues/#create-an-issue
661
     */
662
    public static function getGithubIssueURL($summary, $errorfile, $errorline)
0 ignored issues
show
Unused Code introduced by
The parameter $summary is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errorfile is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errorline is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
663
    {
664
        // POST /repos/:owner/:repo/issues
665
666
        /*{
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
667
            "title": "Found a bug",
668
            "body": "I'm having a problem with this.",
669
            "assignee": "octocat",
670
            "milestone": 1,
671
            "labels": [
672
              "Label1",
673
              "Label2"
674
            ]
675
          }
676
         */
677
    }
678
679
    /**
680
     * This method might be registered to the shutdown handler to catch fatal errors.
681
     */
682
    public static function catchFatalErrors()
683
    {
684
        $lastError = error_get_last();
685
686
        // return early, if there hasn't been an error yet
687
        if (null === $lastError) {
688
            return;
689
        }
690
691
        $fatals = [
692
            E_USER_ERROR      => 'Fatal Error',
693
            E_ERROR           => 'Fatal Error',
694
            E_PARSE           => 'Parse Error',
695
            E_CORE_ERROR      => 'Core Error',
696
            E_CORE_WARNING    => 'Core Warning',
697
            E_COMPILE_ERROR   => 'Compile Error',
698
            E_COMPILE_WARNING => 'Compile Warning',
699
        ];
700
701
        if (isset($fatals[$lastError['type']])) {
702
            self::handle($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
0 ignored issues
show
Bug introduced by
The method handle() does not exist on Koch\Exception\Errorhandler. Did you maybe mean handleErrorAsErrorException()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
703
        }
704
    }
705
}
706