Completed
Push — master ( 0e5dfa...8fd6d1 )
by Ron
03:28
created
src/CoreErrorHandlers.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -28,15 +28,15 @@  discard block
 block discarded – undo
28 28
 	 * @param int|null $bitmask
29 29
 	 */
30 30
 	public static function enableExceptionsForErrors($bitmask = null) {
31
-		set_error_handler(function ($level, $message, $file, $line) use ($bitmask) {
31
+		set_error_handler(function($level, $message, $file, $line) use ($bitmask) {
32 32
 			// PHP-7 fix: What once was an E_STRICT is now an E_WARNING:
33
-			if(preg_match('/^Declaration of .*? should be compatible with/', $message)) {
33
+			if (preg_match('/^Declaration of .*? should be compatible with/', $message)) {
34 34
 				$level = E_STRICT;
35 35
 			}
36 36
 			if (0 === error_reporting()) {
37 37
 				return false;
38 38
 			}
39
-			if($bitmask & $level) {
39
+			if ($bitmask & $level) {
40 40
 				throw new ErrorException($message, 0, $level, $file, $line);
41 41
 			}
42 42
 		});
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	public static function registerAssertionHandler(LoggerInterface $logger, $logLevel) {
50 50
 		static $errorLogger = null;
51
-		if($errorLogger === null) {
51
+		if ($errorLogger === null) {
52 52
 			$errorLogger = new LoggerCollection();
53 53
 			assert_options(ASSERT_ACTIVE, true);
54 54
 			assert_options(ASSERT_WARNING, false);
55
-			assert_options(ASSERT_CALLBACK, function ($file, $line, $message) use ($errorLogger, $logLevel) {
55
+			assert_options(ASSERT_CALLBACK, function($file, $line, $message) use ($errorLogger, $logLevel) {
56 56
 				$errorLogger->log($logLevel, $message, array(
57 57
 					'file' => $file,
58 58
 					'line' => $line
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	public static function registerFatalErrorHandler(LoggerInterface $logger) {
69 69
 		static $errorLogger = null;
70
-		if($errorLogger === null) {
70
+		if ($errorLogger === null) {
71 71
 			$errorLogger = new LoggerCollection();
72 72
 			$errorLevels = self::$phpErrorLevels;
73
-			register_shutdown_function(function () use ($errorLogger, $errorLevels) {
73
+			register_shutdown_function(function() use ($errorLogger, $errorLevels) {
74 74
 				$error = error_get_last();
75
-				if($error['type'] === E_ERROR) {
75
+				if ($error['type'] === E_ERROR) {
76 76
 					$errorLogger = new LogLevelRangeFilter($errorLogger, LogLevel::ERROR);
77 77
 					$errorLogger->log(LogLevel::ALERT, $error['message'], $error);
78 78
 				}
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public static function registerExceptionHandler(LoggerInterface $logger) {
88 88
 		static $errorLogger = null;
89
-		if($errorLogger === null) {
89
+		if ($errorLogger === null) {
90 90
 			$errorLogger = new LoggerCollection();
91
-			set_exception_handler(function ($exception) use ($errorLogger) {
91
+			set_exception_handler(function($exception) use ($errorLogger) {
92 92
 				/** @var \Exception|\Throwable $exception */
93 93
 				$errorLogger = new LogLevelRangeFilter($errorLogger, LogLevel::ERROR);
94 94
 				$errorLogger->log(LogLevel::CRITICAL, $exception->getMessage(), array('exception' => $exception));
95
-				if($exception instanceof Exception) {
95
+				if ($exception instanceof Exception) {
96 96
 					self::printException($exception, "PHP Fatal Error: Uncaught exception: ");
97 97
 					die(1);
98 98
 				}
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param string $messageIntro
107 107
 	 */
108 108
 	private static function printException(Exception $e, $messageIntro = '') {
109
-		$p = function ($format = "\n") {
109
+		$p = function($format = "\n") {
110 110
 			$fp = fopen('php://stderr', 'w');
111 111
 			fwrite($fp, vsprintf($format, array_slice(func_get_args(), 1)));
112 112
 			fclose($fp);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 
115 115
 		$p("%s%s\n", $messageIntro, $e->getMessage());
116 116
 
117
-		$formatStation = function ($idx, $station) use ($p) {
117
+		$formatStation = function($idx, $station) use ($p) {
118 118
 			$defaults = [
119 119
 				'file' => null,
120 120
 				'line' => null,
@@ -125,29 +125,29 @@  discard block
 block discarded – undo
125 125
 			];
126 126
 			$station = array_merge($defaults, $station);
127 127
 			$p("#%- 3s%s:%d\n", $idx, $station['file'] ?: 'unknown', $station['line']);
128
-			if($station['class'] !== null || $station['function'] !== null) {
128
+			if ($station['class'] !== null || $station['function'] !== null) {
129 129
 				$params = [];
130
-				foreach(is_array($station['args']) ? $station['args'] : [] as $argument) {
131
-					if(is_array($argument)) {
130
+				foreach (is_array($station['args']) ? $station['args'] : [] as $argument) {
131
+					if (is_array($argument)) {
132 132
 						$params[] = sprintf('array%d', count($argument));
133
-					} elseif(is_object($argument)) {
133
+					} elseif (is_object($argument)) {
134 134
 						$params[] = sprintf('%s', get_class($argument));
135 135
 					} else {
136 136
 						$params[] = gettype($argument);
137 137
 					}
138 138
 				}
139
-				if(strpos($station['function'], '{closure}') !== false && $station['class'] !== null) {
139
+				if (strpos($station['function'], '{closure}') !== false && $station['class'] !== null) {
140 140
 					$station['function'] = '{closure}';
141 141
 				}
142 142
 				$p("    %s%s%s%s%s%s\n", $station['class'], $station['type'], $station['function'], "(", join(', ', $params), ")");
143 143
 			}
144 144
 		};
145 145
 
146
-		foreach($e->getTrace() as $idx => $station) {
146
+		foreach ($e->getTrace() as $idx => $station) {
147 147
 			$formatStation($idx, $station);
148 148
 		}
149 149
 
150
-		if($e->getPrevious() instanceof Exception) {
150
+		if ($e->getPrevious() instanceof Exception) {
151 151
 			$p();
152 152
 			self::printException($e->getPrevious(), 'Previous: ');
153 153
 		}
Please login to merge, or discard this patch.