for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Protoku\Exceptions;
use ErrorException;
use Protoku\Interfaces\FormatterInterface;
class Handler
{
const ERROR_HANDLER = 'handleError';
const EXCEPTION_HANDLER = 'handleException';
/**
* @var FormatterInterface
*/
private $formatter;
* Handler constructor.
*
* @param FormatterInterface $formatter
public function __construct(FormatterInterface $formatter)
$this->formatter = $formatter;
}
* Register the PHP error handler.
* @return void
protected function registerErrorHandler()
set_error_handler(array($this, self::ERROR_HANDLER));
* Register the PHP exception handler.
protected function registerExceptionHandler()
set_exception_handler(array($this, self::EXCEPTION_HANDLER));
* @param int $level
* @param string $message
* @param string $file
* @param int $line
* @param array $context
* @throws ErrorException
public function handleError(int $level, string $message, string $file = '', int $line = 0, array $context = [])
$context
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
throw new ErrorException($message, 0, $level, $file, $line);
public function handleException(\Throwable $e)
ob_start();
$response = $this->formatter->format($e);
ob_end_clean();
http_response_code(500);
print $response;
return;
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.