@@ -35,13 +35,12 @@ class ErrorHandler
3535 /**
3636 * Returns an array of lines from a file.
3737 *
38- * @access public
3938 * @param string $file File in which you want to highlight a line
4039 * @param int $line Line number to highlight
4140 * @param int $padding (optional) Number of padding lines
4241 * @return array
4342 */
44- protected static function highlightCode ($ file , $ line , $ padding = 6 )
43+ protected static function highlightCode (string $ file , int $ line , int $ padding = 6 ) : array
4544 {
4645 if ( ! is_readable ($ file )) {
4746 return false ;
@@ -78,13 +77,13 @@ protected static function highlightCode($file, $line, $padding = 6)
7877 /**
7978 * Converts errors to ErrorExceptions.
8079 *
81- * @param integer $code The error code
80+ * @param int $code The error code
8281 * @param string $message The error message
8382 * @param string $file The filename where the error occurred
84- * @param integer $line The line number where the error occurred
85- * @return boolean
83+ * @param int $line The line number where the error occurred
84+ * @return bool
8685 */
87- public static function error ($ code , $ message , $ file , $ line )
86+ public static function error (int $ code , string $ message , string $ file , int $ line ) : bool
8887 {
8988 // If isset error_reporting and $code then throw new error exception
9089 if ((error_reporting () & $ code ) !== 0 ) {
@@ -111,7 +110,7 @@ public static function error($code, $message, $file, $line)
111110 ErrorHandler::writeLogs ("{$ error ['type ' ]}: {$ error ['message ' ]} in {$ error ['file ' ]} at line {$ error ['line ' ]}" );
112111
113112 } else {
114- throw new ErrorException ($ message , $ code , 0 , $ file , $ line );
113+ throw new \ ErrorException ($ message , $ code , 0 , $ file , $ line );
115114 }
116115 }
117116
@@ -125,7 +124,7 @@ public static function error($code, $message, $file, $line)
125124 * @param string $string String
126125 * @return string
127126 */
128- protected static function highlightString ($ string )
127+ protected static function highlightString (string $ string ) : string
129128 {
130129 $ search = array ("\r\n" , "\n\r" , "\r" , "\n" , '<code> ' , '</code> ' , '<span style="color: #0000BB"><?php ' , '#$@r4!/* ' );
131130 $ replace = array ('' , '' , '' , '' , '' , '' , '<span style="color: #0000BB"> ' , '/* ' );
@@ -136,11 +135,10 @@ protected static function highlightString($string)
136135 /**
137136 * Modifies the backtrace array.
138137 *
139- * @access protected
140138 * @param array $backtrace Array returned by the getTrace() method of an exception object
141139 * @return array
142140 */
143- protected static function formatBacktrace ($ backtrace )
141+ protected static function formatBacktrace (array $ backtrace ) : array
144142 {
145143 if (is_array ($ backtrace ) === false || count ($ backtrace ) === 0 ) {
146144 return $ backtrace ;
@@ -223,7 +221,7 @@ public static function fatal()
223221 $ e = error_get_last ();
224222
225223 if ($ e !== null && (error_reporting () & $ e ['type ' ]) !== 0 ) {
226- ErrorHandler::exception (new ErrorException ($ e ['message ' ], $ e ['type ' ], 0 , $ e ['file ' ], $ e ['line ' ]));
224+ ErrorHandler::exception (new \ ErrorException ($ e ['message ' ], $ e ['type ' ], 0 , $ e ['file ' ], $ e ['line ' ]));
227225
228226 exit (1 );
229227 }
@@ -232,11 +230,10 @@ public static function fatal()
232230 /**
233231 * Writes message to log.
234232 *
235- * @access public
236233 * @param string $message The message to write to the log
237- * @return boolean
234+ * @return bool
238235 */
239- public static function writeLogs ($ message )
236+ public static function writeLogs (string $ message ) : bool
240237 {
241238 return (bool ) file_put_contents (rtrim (LOGS_PATH , '/ ' ) . '/ ' . gmdate ('Y_m_d ' ) . '.log ' ,
242239 '[ ' . gmdate ('d-M-Y H:i:s ' ) . '] ' . $ message . PHP_EOL ,
@@ -246,7 +243,6 @@ public static function writeLogs($message)
246243 /**
247244 * Handles uncaught exceptions and returns a pretty error screen.
248245 *
249- * @access public
250246 * @param Exception $exception An exception object
251247 */
252248 public static function exception ($ exception )
@@ -263,7 +259,7 @@ public static function exception($exception)
263259 $ error ['line ' ] = $ exception ->getLine ();
264260
265261 // Determine error type
266- if ($ exception instanceof ErrorException) {
262+ if ($ exception instanceof \ ErrorException) {
267263 $ error ['type ' ] = 'ErrorException: ' ;
268264 $ error ['type ' ] .= in_array ($ error ['code ' ], array_keys (ErrorHandler::$ levels )) ? ErrorHandler::$ levels [$ error ['code ' ]] : 'Unknown Error ' ;
269265 } else {
@@ -280,7 +276,7 @@ public static function exception($exception)
280276
281277 $ error ['backtrace ' ] = $ exception ->getTrace ();
282278
283- if ($ exception instanceof ErrorException) {
279+ if ($ exception instanceof \ ErrorException) {
284280 $ error ['backtrace ' ] = array_slice ($ error ['backtrace ' ], 1 ); //Remove call to error handler from backtrace
285281 }
286282
0 commit comments