@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * @param int $line |
| 24 | 24 | * @return void |
| 25 | 25 | */ |
| 26 | - public static function error( $severity, $message, $file, $line ) { |
|
| 26 | + public static function error($severity, $message, $file, $line) { |
|
| 27 | 27 | |
| 28 | 28 | // Latest Twig raises a warning when accessing missing cached views - we can ignore it |
| 29 | - if( preg_match('/filemtime/', $message) ) |
|
| 29 | + if (preg_match('/filemtime/', $message)) |
|
| 30 | 30 | return; |
| 31 | 31 | |
| 32 | 32 | // if the error was a type hint failure then throw an InvalidArgumentException instead |
| 33 | - elseif( preg_match('/^Argument (\d+) passed to ([\w\\\\]+)::(\w+)\(\) must be an instance of ([\w\\\\]+), ([\w\\\\]+) given, called in ([\w\s\.\/_-]+) on line (\d+)/', $message, $m) ) |
|
| 33 | + elseif (preg_match('/^Argument (\d+) passed to ([\w\\\\]+)::(\w+)\(\) must be an instance of ([\w\\\\]+), ([\w\\\\]+) given, called in ([\w\s\.\/_-]+) on line (\d+)/', $message, $m)) |
|
| 34 | 34 | throw new \InvalidArgumentException("Argument {$m[1]} to {$m[2]}::{$m[3]}() should be an instance of {$m[4]}, {$m[5]} given", $severity, new \ErrorException($message, 0, $severity, $m[6], $m[7])); |
| 35 | 35 | |
| 36 | 36 | // convert the error to an exception |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | * @param string $error_page the file containing the error page to include for production web apps |
| 45 | 45 | * @return void |
| 46 | 46 | */ |
| 47 | - public static function exception( \Exception $error, $error_page, $log = true ) { |
|
| 47 | + public static function exception(\Exception $error, $error_page, $log = true) { |
|
| 48 | 48 | |
| 49 | - if( $log ) |
|
| 49 | + if ($log) |
|
| 50 | 50 | static::logException($error); |
| 51 | 51 | |
| 52 | - if( Yolk::isCLI() ) { |
|
| 52 | + if (Yolk::isCLI()) { |
|
| 53 | 53 | Yolk::dump($error); |
| 54 | 54 | } |
| 55 | 55 | // debug web app |
| 56 | - elseif( Yolk::isDebug() ) { |
|
| 57 | - require __DIR__. '/error.debug.php'; |
|
| 56 | + elseif (Yolk::isDebug()) { |
|
| 57 | + require __DIR__.'/error.debug.php'; |
|
| 58 | 58 | } |
| 59 | 59 | // production web app |
| 60 | 60 | else { |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * @param \Exception $error |
| 69 | 69 | * @return void |
| 70 | 70 | */ |
| 71 | - public static function logException( \Exception $error ) { |
|
| 71 | + public static function logException(\Exception $error) { |
|
| 72 | 72 | |
| 73 | 73 | // fatal errors will already have been error_log()'d |
| 74 | - if( !static::isFatal($error) ) { |
|
| 75 | - $location = $error->getFile(). ':'. $error->getLine(); |
|
| 74 | + if (!static::isFatal($error)) { |
|
| 75 | + $location = $error->getFile().':'.$error->getLine(); |
|
| 76 | 76 | // type hinting error - make sure we give the correct location |
| 77 | - if( ($error instanceof \InvalidArgumentException) && ($error->getPrevious() instanceof \ErrorException) ) |
|
| 78 | - $location = $error->getPrevious()->getFile(). ':'. $error->getPrevious()->getLine(); |
|
| 79 | - error_log(get_class($error). ': '. $error->getMessage(). " [{$location}]"); |
|
| 77 | + if (($error instanceof \InvalidArgumentException) && ($error->getPrevious() instanceof \ErrorException)) |
|
| 78 | + $location = $error->getPrevious()->getFile().':'.$error->getPrevious()->getLine(); |
|
| 79 | + error_log(get_class($error).': '.$error->getMessage()." [{$location}]"); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public static function checkFatal() { |
| 89 | 89 | $error = error_get_last(); |
| 90 | - if( $error && static::isFatal($error['type']) ) { |
|
| 90 | + if ($error && static::isFatal($error['type'])) { |
|
| 91 | 91 | Yolk::exception(new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | * @param \Exception|integer $error |
| 98 | 98 | * @return boolean |
| 99 | 99 | */ |
| 100 | - protected static function isFatal( $error ) { |
|
| 100 | + protected static function isFatal($error) { |
|
| 101 | 101 | |
| 102 | - if( $error instanceof \Exception ) |
|
| 102 | + if ($error instanceof \Exception) |
|
| 103 | 103 | return false; |
| 104 | 104 | |
| 105 | 105 | $fatal = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR; |
| 106 | 106 | |
| 107 | - if( $error instanceof \ErrorException ) |
|
| 107 | + if ($error instanceof \ErrorException) |
|
| 108 | 108 | $error = $error->getSeverity(); |
| 109 | 109 | |
| 110 | 110 | return (bool) ($error & $fatal); |
@@ -26,12 +26,14 @@ discard block |
||
| 26 | 26 | public static function error( $severity, $message, $file, $line ) { |
| 27 | 27 | |
| 28 | 28 | // Latest Twig raises a warning when accessing missing cached views - we can ignore it |
| 29 | - if( preg_match('/filemtime/', $message) ) |
|
| 30 | - return; |
|
| 29 | + if( preg_match('/filemtime/', $message) ) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 31 | 32 | |
| 32 | 33 | // if the error was a type hint failure then throw an InvalidArgumentException instead |
| 33 | - elseif( preg_match('/^Argument (\d+) passed to ([\w\\\\]+)::(\w+)\(\) must be an instance of ([\w\\\\]+), ([\w\\\\]+) given, called in ([\w\s\.\/_-]+) on line (\d+)/', $message, $m) ) |
|
| 34 | - throw new \InvalidArgumentException("Argument {$m[1]} to {$m[2]}::{$m[3]}() should be an instance of {$m[4]}, {$m[5]} given", $severity, new \ErrorException($message, 0, $severity, $m[6], $m[7])); |
|
| 34 | + elseif( preg_match('/^Argument (\d+) passed to ([\w\\\\]+)::(\w+)\(\) must be an instance of ([\w\\\\]+), ([\w\\\\]+) given, called in ([\w\s\.\/_-]+) on line (\d+)/', $message, $m) ) { |
|
| 35 | + throw new \InvalidArgumentException("Argument {$m[1]} to {$m[2]}::{$m[3]}() should be an instance of {$m[4]}, {$m[5]} given", $severity, new \ErrorException($message, 0, $severity, $m[6], $m[7])); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // convert the error to an exception |
| 37 | 39 | throw new \ErrorException($message, 0, $severity, $file, $line); |
@@ -46,8 +48,9 @@ discard block |
||
| 46 | 48 | */ |
| 47 | 49 | public static function exception( \Exception $error, $error_page, $log = true ) { |
| 48 | 50 | |
| 49 | - if( $log ) |
|
| 50 | - static::logException($error); |
|
| 51 | + if( $log ) { |
|
| 52 | + static::logException($error); |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | if( Yolk::isCLI() ) { |
| 53 | 56 | Yolk::dump($error); |
@@ -74,8 +77,9 @@ discard block |
||
| 74 | 77 | if( !static::isFatal($error) ) { |
| 75 | 78 | $location = $error->getFile(). ':'. $error->getLine(); |
| 76 | 79 | // type hinting error - make sure we give the correct location |
| 77 | - if( ($error instanceof \InvalidArgumentException) && ($error->getPrevious() instanceof \ErrorException) ) |
|
| 78 | - $location = $error->getPrevious()->getFile(). ':'. $error->getPrevious()->getLine(); |
|
| 80 | + if( ($error instanceof \InvalidArgumentException) && ($error->getPrevious() instanceof \ErrorException) ) { |
|
| 81 | + $location = $error->getPrevious()->getFile(). ':'. $error->getPrevious()->getLine(); |
|
| 82 | + } |
|
| 79 | 83 | error_log(get_class($error). ': '. $error->getMessage(). " [{$location}]"); |
| 80 | 84 | } |
| 81 | 85 | |
@@ -99,13 +103,15 @@ discard block |
||
| 99 | 103 | */ |
| 100 | 104 | protected static function isFatal( $error ) { |
| 101 | 105 | |
| 102 | - if( $error instanceof \Exception ) |
|
| 103 | - return false; |
|
| 106 | + if( $error instanceof \Exception ) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 104 | 109 | |
| 105 | 110 | $fatal = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR; |
| 106 | 111 | |
| 107 | - if( $error instanceof \ErrorException ) |
|
| 108 | - $error = $error->getSeverity(); |
|
| 112 | + if( $error instanceof \ErrorException ) { |
|
| 113 | + $error = $error->getSeverity(); |
|
| 114 | + } |
|
| 109 | 115 | |
| 110 | 116 | return (bool) ($error & $fatal); |
| 111 | 117 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | // use default php error handler |
| 6 | 6 | set_error_handler( |
| 7 | - function( $severity, $message, $file, $line ) { |
|
| 7 | + function($severity, $message, $file, $line) { |
|
| 8 | 8 | return false; |
| 9 | 9 | } |
| 10 | 10 | ); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | ]; |
| 30 | 30 | |
| 31 | 31 | $err = [ |
| 32 | - 'name' => '\\'. get_class($error), |
|
| 32 | + 'name' => '\\'.get_class($error), |
|
| 33 | 33 | 'code' => $error->getCode(), |
| 34 | 34 | 'message' => $error->getMessage(), |
| 35 | 35 | 'file' => $error->getFile(), |
@@ -37,16 +37,16 @@ discard block |
||
| 37 | 37 | 'trace' => $error->getTrace(), |
| 38 | 38 | 'previous' => $error->getPrevious(), |
| 39 | 39 | ]; |
| 40 | -if( $error instanceof \ErrorException ) { |
|
| 40 | +if ($error instanceof \ErrorException) { |
|
| 41 | 41 | $err['name'] = $names[$error->getSeverity()]; |
| 42 | 42 | } |
| 43 | -elseif( ($error instanceof \InvalidArgumentException) && ($err['previous'] instanceof \ErrorException) ) { |
|
| 43 | +elseif (($error instanceof \InvalidArgumentException) && ($err['previous'] instanceof \ErrorException)) { |
|
| 44 | 44 | $err['file'] = $err['previous']->getFile(); |
| 45 | 45 | $err['line'] = $err['previous']->getLine(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // it's an error - don't send a 200 code! |
| 49 | -if( !headers_sent() && (http_response_code() == 200) ) |
|
| 49 | +if (!headers_sent() && (http_response_code() == 200)) |
|
| 50 | 50 | header("HTTP/1.0 500 Internal Server Error"); |
| 51 | 51 | |
| 52 | 52 | ?><!DOCTYPE html> |
@@ -151,20 +151,20 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | </div> |
| 153 | 153 | |
| 154 | -<?php if( $err['trace'] ) { ?> |
|
| 154 | +<?php if ($err['trace']) { ?> |
|
| 155 | 155 | <div id="trace"> |
| 156 | 156 | <h2>Trace:</h2> |
| 157 | 157 | <ol> |
| 158 | - <?php foreach( $err['trace'] as $i => $item ) { ?> |
|
| 158 | + <?php foreach ($err['trace'] as $i => $item) { ?> |
|
| 159 | 159 | <li class="panel"> |
| 160 | 160 | <?php |
| 161 | - if( isset($item['file']) ) { ?> |
|
| 161 | + if (isset($item['file'])) { ?> |
|
| 162 | 162 | <p> |
| 163 | 163 | <strong>File:</strong> <code><?=$item['file']; ?></code> |
| 164 | - <?php if( isset($item['line']) ) { ?> <strong>Line:</strong> <code><?=$item['line'] ?></code><?php } ?> |
|
| 164 | + <?php if (isset($item['line'])) { ?> <strong>Line:</strong> <code><?=$item['line'] ?></code><?php } ?> |
|
| 165 | 165 | </p> |
| 166 | 166 | <?php } ?> |
| 167 | - <p><strong>Function: </strong><code><?=isset($item['class']) ? $item['class']. $item['type'] : ''?><?=$item['function']. '()'; ?></code></p> |
|
| 167 | + <p><strong>Function: </strong><code><?=isset($item['class']) ? $item['class'].$item['type'] : ''?><?=$item['function'].'()'; ?></code></p> |
|
| 168 | 168 | </li> |
| 169 | 169 | <?php } ?> |
| 170 | 170 | </ol> |
@@ -39,15 +39,15 @@ |
||
| 39 | 39 | ]; |
| 40 | 40 | if( $error instanceof \ErrorException ) { |
| 41 | 41 | $err['name'] = $names[$error->getSeverity()]; |
| 42 | -} |
|
| 43 | -elseif( ($error instanceof \InvalidArgumentException) && ($err['previous'] instanceof \ErrorException) ) { |
|
| 42 | +} elseif( ($error instanceof \InvalidArgumentException) && ($err['previous'] instanceof \ErrorException) ) { |
|
| 44 | 43 | $err['file'] = $err['previous']->getFile(); |
| 45 | 44 | $err['line'] = $err['previous']->getLine(); |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | // it's an error - don't send a 200 code! |
| 49 | -if( !headers_sent() && (http_response_code() == 200) ) |
|
| 48 | +if( !headers_sent() && (http_response_code() == 200) ) { |
|
| 50 | 49 | header("HTTP/1.0 500 Internal Server Error"); |
| 50 | +} |
|
| 51 | 51 | |
| 52 | 52 | ?><!DOCTYPE html> |
| 53 | 53 | <html> |