GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GenericExceptionHandler::handler()   F
last analyzed

Complexity

Conditions 13
Paths 408

Size

Total Lines 68
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 13
eloc 35
c 2
b 0
f 0
nc 408
nop 1
dl 0
loc 68
rs 3.2722

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * @package core
4
 */
5
6
/**
7
 * GenericExceptionHandler will handle any uncaught exceptions thrown in
8
 * Symphony. Additionally, all errors in Symphony that are raised to Exceptions
9
 * will be handled by this class.
10
 * It is possible for Exceptions to be caught by their own `ExceptionHandler` which can
11
 * override the `render` function so that it can be displayed to the user appropriately.
12
 */
13
class GenericExceptionHandler
14
{
15
    /**
16
     * Whether the `GenericExceptionHandler` should handle exceptions. Defaults to true
17
     * @var boolean
18
     */
19
    public static $enabled = true;
20
21
    /**
22
     * An instance of the Symphony Log class, used to write errors to the log
23
     * @var Log
24
     */
25
    private static $_Log = null;
26
27
    /**
28
     * Initialise will set the error handler to be the `__CLASS__::handler` function.
29
     *
30
     * @param Log $Log
31
     *  An instance of a Symphony Log object to write errors to
32
     */
33
    public static function initialise(Log $Log = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$Log" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$Log"; expected 0 but found 1
Loading history...
34
    {
35
        if (!is_null($Log)) {
36
            self::$_Log = $Log;
37
        }
38
39
        set_exception_handler(array(__CLASS__, 'handler'));
40
        register_shutdown_function(array(__CLASS__, 'shutdown'));
41
    }
42
43
    /**
44
     * Retrieves a window of lines before and after the line where the error
45
     * occurred so that a developer can help debug the exception
46
     *
47
     * @param integer $line
48
     *  The line where the error occurred.
49
     * @param string $file
50
     *  The file that holds the logic that caused the error.
51
     * @param integer $window
52
     *  The number of lines either side of the line where the error occurred
53
     *  to show
54
     * @return array
55
     */
56
    protected static function __nearbyLines($line, $file, $window = 5)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$window" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$window"; expected 0 but found 1
Loading history...
57
    {
58
        if (!file_exists($file)) {
59
            return array();
60
        }
61
62
        return array_slice(file($file), ($line - 1) - $window, $window * 2, true);
0 ignored issues
show
Bug introduced by
It seems like file($file) can also be of type false; however, parameter $array of array_slice() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        return array_slice(/** @scrutinizer ignore-type */ file($file), ($line - 1) - $window, $window * 2, true);
Loading history...
63
    }
64
65
    /**
66
     * This function's goal is to validate the `$e` parameter in order to ensure
67
     * that the object is an `Exception` or a `Throwable` instance.
68
     * @since Symphony 2.7.0
69
     *
70
     * @param Throwable $e
71
     *  The Throwable object that will be validated
72
     * @return boolean
73
     *  true when valid, false otherwise
74
     */
75
    public static function isValidThrowable($e)
76
    {
77
        return $e instanceof Exception || $e instanceof Throwable;
78
    }
79
80
    /**
81
     * The handler function is given an Throwable and will call it's render
82
     * function to display the Throwable to a user. After calling the render
83
     * function, the output is displayed and then exited to prevent any further
84
     * logic from occurring.
85
     *
86
     * @since Symphony 2.7.0
87
     *  This function works with both Exception and Throwable
88
     *  Supporting both PHP 5.6 and 7 forces use to not qualify the $e parameter
89
     *
90
     * @param Throwable $e
91
     *  The Throwable object
92
     * @return string
93
     *  The result of the Throwable's render function
94
     */
95
    public static function handler($e)
96
    {
97
        $output = '';
98
99
        try {
100
            // Instead of just throwing an empty page, return a 404 page.
101
            if (self::$enabled !== true) {
102
                $e = new FrontendPageNotFoundException();
103
            }
104
105
            // Validate the type, resolve to a 404 if not valid
106
            if (!static::isValidThrowable($e)) {
107
                $e = new FrontendPageNotFoundException();
108
            }
109
110
            $exception_type = get_class($e);
111
112
            if (class_exists("{$exception_type}Handler") && method_exists("{$exception_type}Handler", 'render')) {
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $exception_type instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
113
                $class = "{$exception_type}Handler";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $exception_type instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
114
            } else {
115
                $class = __CLASS__;
116
            }
117
118
            // Exceptions should be logged if they are not caught.
119
            if (self::$_Log instanceof Log) {
0 ignored issues
show
introduced by
self::_Log is always a sub-type of Log.
Loading history...
120
                self::$_Log->pushExceptionToLog($e, true);
121
            }
122
123
            $output = call_user_func(array($class, 'render'), $e);
124
125
        // If an exception was raised trying to render the exception, fall back
126
        // to the generic exception handler
127
        } catch (Exception $e) {
128
            try {
129
                $output = call_user_func(array('GenericExceptionHandler', 'render'), $e);
130
131
            // If the generic exception handler couldn't do it, well we're in bad
132
            // shape, just output a plaintext response!
133
            } catch (Exception $e) {
134
                echo "<pre>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <pre> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
135
                echo 'A severe error occurred whilst trying to handle an exception, check the Symphony log for more details' . PHP_EOL;
136
                echo $e->getMessage() . ' on ' . $e->getLine() . ' of file ' . $e->getFile() . PHP_EOL;
137
                exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
138
            }
139
        }
140
141
        // Pending nothing disasterous, we should have `$e` and `$output` values here.
142
        if (!headers_sent()) {
143
            cleanup_session_cookies();
144
145
            // Inspect the exception to determine the best status code
146
            $httpStatus = null;
147
            if ($e instanceof SymphonyErrorPage) {
148
                $httpStatus = $e->getHttpStatusCode();
149
            } elseif ($e instanceof FrontendPageNotFoundException) {
150
                $httpStatus = Page::HTTP_STATUS_NOT_FOUND;
151
            }
152
153
            if (!$httpStatus || $httpStatus == Page::HTTP_STATUS_OK) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $httpStatus of type integer|null is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
154
                $httpStatus = Page::HTTP_STATUS_ERROR;
155
            }
156
157
            Page::renderStatusCode($httpStatus);
158
            header('Content-Type: text/html; charset=utf-8');
159
        }
160
161
        echo $output;
162
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
163
    }
164
165
    /**
166
     * Returns the path to the error-template by looking at the `WORKSPACE/template/`
167
     * directory, then at the `TEMPLATES`  directory for the convention `*.tpl`. If
168
     * the template is not found, `false` is returned
169
     *
170
     * @since Symphony 2.3
171
     * @param string $name
172
     *  Name of the template
173
     * @return string|false
174
     *  String, which is the path to the template if the template is found,
175
     *  false otherwise
176
     */
177
    public static function getTemplate($name)
178
    {
179
        $format = '%s/%s.tpl';
180
181
        if (file_exists($template = sprintf($format, WORKSPACE . '/template', $name))) {
0 ignored issues
show
Bug introduced by
The constant WORKSPACE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
182
            return $template;
183
        } elseif (file_exists($template = sprintf($format, TEMPLATE, $name))) {
0 ignored issues
show
Bug introduced by
The constant TEMPLATE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
184
            return $template;
185
        } else {
186
            return false;
187
        }
188
    }
189
190
    /**
191
     * The render function will take an Throwable and output a HTML page
192
     *
193
     * @since Symphony 2.7.0
194
     *  This function works with both Exception and Throwable
195
     *
196
     * @param Throwable $e
197
     *  The Throwable object
198
     * @return string
199
     *  An HTML string
200
     */
201
    public static function render($e)
202
    {
203
        $lines = null;
204
205
        foreach (self::__nearByLines($e->getLine(), $e->getFile()) as $line => $string) {
206
            $lines .= sprintf(
207
                '<li%s><strong>%d</strong> <code>%s</code></li>',
208
                (($line+1) == $e->getLine() ? ' class="error"' : null),
209
                ++$line,
210
                str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', htmlspecialchars($string))
211
            );
212
        }
213
214
        $trace = null;
215
216
        foreach ($e->getTrace() as $t) {
217
            $trace .= sprintf(
218
                '<li><code><em>[%s:%d]</em></code></li><li><code>&#160;&#160;&#160;&#160;%s%s%s();</code></li>',
219
                (isset($t['file']) ? $t['file'] : null),
220
                (isset($t['line']) ? $t['line'] : null),
221
                (isset($t['class']) ? $t['class'] : null),
222
                (isset($t['type']) ? $t['type'] : null),
223
                $t['function']
224
            );
225
        }
226
227
        $queries = null;
228
229
        if (is_object(Symphony::Database())) {
230
            $debug = Symphony::Database()->debug();
231
232
            if (!empty($debug)) {
233
                foreach ($debug as $query) {
234
                    $queries .= sprintf(
235
                        '<li><em>[%01.4f]</em><code> %s;</code> </li>',
236
                        (isset($query['execution_time']) ? $query['execution_time'] : null),
237
                        htmlspecialchars($query['query'])
238
                    );
239
                }
240
            }
241
        }
242
243
        return self::renderHtml(
244
            'fatalerror.generic',
245
            ($e instanceof ErrorException ? GenericErrorHandler::$errorTypeStrings[$e->getSeverity()] : 'Fatal Error'),
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
246
            $e->getMessage(),
247
            $e->getFile(),
248
            $e->getLine(),
249
            $lines,
250
            $trace,
251
            $queries
252
        );
253
    }
254
255
    /**
256
     * The shutdown function will capture any fatal errors and format them as a
257
     * usual Symphony page.
258
     *
259
     * @since Symphony 2.4
260
     */
261
    public static function shutdown()
262
    {
263
        $last_error = error_get_last();
264
265
        if (!is_null($last_error) && $last_error['type'] === E_ERROR) {
0 ignored issues
show
introduced by
The condition is_null($last_error) is always false.
Loading history...
266
            $code = $last_error['type'];
267
            $message = $last_error['message'];
268
            $file = $last_error['file'];
269
            $line = $last_error['line'];
270
271
            try {
272
                // Log the error message
273
                if (self::$_Log instanceof Log) {
0 ignored issues
show
introduced by
self::_Log is always a sub-type of Log.
Loading history...
274
                    self::$_Log->pushToLog(sprintf(
275
                        '%s %s: %s%s%s',
276
                        __CLASS__,
277
                        $code,
278
                        $message,
279
                        ($line ? " on line $line" : null),
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $line instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
280
                        ($file ? " of file $file" : null)
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $file instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
281
                    ), $code, true);
282
                }
283
284
                ob_clean();
285
286
                // Display the error message
287
                echo self::renderHtml(
288
                    'fatalerror.fatal',
289
                    'Fatal Error',
290
                    $message,
291
                    $file,
292
                    $line
293
                );
294
            } catch (Exception $e) {
295
                echo "<pre>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <pre> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
296
                echo 'A severe error occurred whilst trying to handle an exception, check the Symphony log for more details' . PHP_EOL;
297
                echo $e->getMessage() . ' on ' . $e->getLine() . ' of file ' . $e->getFile() . PHP_EOL;
298
            }
299
        }
300
    }
301
302
    /**
303
     * This function will fetch the desired `$template`, and output the
304
     * Throwable in a user friendly way.
305
     *
306
     * @since Symphony 2.4
307
     * @param string $template
308
     *  The template name, which should correspond to something in the TEMPLATE
309
     *  directory, eg `fatalerror.fatal`.
310
     *
311
     * @since Symphony 2.7.0
312
     *  This function works with both Exception and Throwable
313
     *
314
     * @param string $heading
315
     * @param string $message
316
     * @param string $file
317
     * @param string $line
318
     * @param string $lines
319
     * @param string $trace
320
     * @param string $queries
321
     * @return string
322
     *  The HTML of the formatted error message.
323
     */
324
    public static function renderHtml($template, $heading, $message, $file = null, $line = null, $lines = null, $trace = null, $queries = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$file" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$file"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$line" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$line"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$lines" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$lines"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$trace" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$trace"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$queries" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$queries"; expected 0 but found 1
Loading history...
325
    {
326
        $html = sprintf(
327
            file_get_contents(self::getTemplate($template)),
0 ignored issues
show
Bug introduced by
It seems like self::getTemplate($template) can also be of type false; however, parameter $filename of file_get_contents() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

327
            file_get_contents(/** @scrutinizer ignore-type */ self::getTemplate($template)),
Loading history...
328
            $heading,
329
            General::unwrapCDATA($message),
330
            $file,
331
            $line,
332
            $lines,
333
            $trace,
334
            $queries
335
        );
336
337
        $html = str_replace('{ASSETS_URL}', ASSETS_URL, $html);
0 ignored issues
show
Bug introduced by
The constant ASSETS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
338
        $html = str_replace('{SYMPHONY_URL}', SYMPHONY_URL, $html);
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
339
        $html = str_replace('{URL}', URL, $html);
0 ignored issues
show
Bug introduced by
The constant URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
340
341
        return $html;
342
    }
343
}
344
345
/**
346
 * `GenericErrorHandler` will catch any warnings or notices thrown by PHP and
347
 * raise the errors to Exceptions so they can be dealt with by the
348
 * `GenericExceptionHandler`. The type of errors that are raised to Exceptions
349
 * depends on the `error_reporting` level. All errors raised, except
350
 * `E_NOTICE` and `E_STRICT` are written to the Symphony log.
351
 */
352
class GenericErrorHandler
353
{
354
    /**
355
     * Whether the error handler is enabled or not, defaults to true.
356
     * Setting to false will prevent any Symphony error handling from occurring
357
     * @var boolean
358
     */
359
    public static $enabled = true;
360
361
    /**
362
     * An instance of the Log class, used to write errors to the log
363
     * @var Log
364
     */
365
    private static $_Log = null;
366
367
    /**
368
     * Whether to log errors or not.
369
     * This one is to be used temporarily, e.g., when PHP function is
370
     * supposed to error out and throw warning and log should be kept clean.
371
     *
372
     * @since Symphony 2.2.2
373
     * @var boolean
374
     * @example
375
     *  GenericErrorHandler::$logDisabled = true;
376
     *  DoSomethingThatEndsWithWarningsYouDoNotWantInLogs();
377
     *  GenericErrorHandler::$logDisabled = false;
378
     */
379
    public static $logDisabled = false;
380
381
    /**
382
     * An associative array with the PHP error constant as a key, and
383
     * a string describing that constant as the value
384
     * @var array
385
     */
386
    public static $errorTypeStrings = array(
387
        E_ERROR                 => 'Fatal Error',
388
        E_WARNING               => 'Warning',
389
        E_PARSE                 => 'Parsing Error',
390
        E_NOTICE                => 'Notice',
391
392
        E_CORE_ERROR            => 'Core Error',
393
        E_CORE_WARNING          => 'Core Warning',
394
        E_COMPILE_ERROR         => 'Compile Error',
395
        E_COMPILE_WARNING       => 'Compile Warning',
396
397
        E_USER_NOTICE           => 'User Notice',
398
        E_USER_WARNING          => 'User Warning',
399
        E_USER_ERROR            => 'User Error',
400
401
        E_STRICT                => 'Strict Notice',
402
        E_RECOVERABLE_ERROR     => 'Recoverable Error',
403
        E_DEPRECATED            => 'Deprecated Warning'
404
    );
405
406
    /**
407
     * Initialise will set the error handler to be the `__CLASS__::handler`
408
     * function.
409
     *
410
     * @param Log|null $Log (optional)
411
     *  An instance of a Symphony Log object to write errors to
412
     */
413
    public static function initialise(Log $Log = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$Log" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$Log"; expected 0 but found 1
Loading history...
414
    {
415
        if (!is_null($Log)) {
416
            self::$_Log = $Log;
417
        }
418
419
        set_error_handler(array(__CLASS__, 'handler'), error_reporting());
420
    }
421
422
    /**
423
     * Determines if the error handler is enabled by checking that error_reporting
424
     * is set in the php config and that $enabled is true
425
     *
426
     * @return boolean
427
     */
428
    public static function isEnabled()
429
    {
430
        return (bool)error_reporting() && self::$enabled;
431
    }
432
433
    /**
434
     * The handler function will write the error to the `$Log` if it is not `E_NOTICE`
435
     * or `E_STRICT` before raising the error as an Exception. This allows all `E_WARNING`
436
     * to actually be captured by an Exception handler.
437
     *
438
     * @param integer $code
439
     *  The error code, one of the PHP error constants
440
     * @param string $message
441
     *  The message of the error, this will be written to the log and
442
     *  displayed as the exception message
443
     * @param string $file
444
     *  The file that holds the logic that caused the error. Defaults to null
445
     * @param integer $line
446
     *  The line where the error occurred.
447
     * @throws ErrorException
448
     * @return boolean
449
     *  Usually a string of HTML that will displayed to a user
450
     */
451
    public static function handler($code, $message, $file = null, $line = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$file" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$file"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$line" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$line"; expected 0 but found 1
Loading history...
452
    {
453
        // Only log if the error won't be raised to an exception and the error is not `E_STRICT`
454
        if (!self::$logDisabled && !in_array($code, array(E_STRICT)) && self::$_Log instanceof Log) {
455
            self::$_Log->pushToLog(sprintf(
456
                '%s %s: %s%s%s',
457
                __CLASS__,
458
                $code,
459
                $message,
460
                ($line ? " on line $line" : null),
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $line instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
461
                ($file ? " of file $file" : null)
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $file instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
462
            ), $code, true);
463
        }
464
465
        if (self::isEnabled()) {
466
            throw new ErrorException($message, 0, $code, $file, $line);
467
        }
468
469
        // This is needed to stop php from processing the error
470
        // See http://php.net/manual/en/function.set-error-handler.php
471
        return true;
472
    }
473
}
474