Skip to content

Commit

Permalink
Fixed codeclimate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xujiajun committed Oct 19, 2017
1 parent 4987aa6 commit bc1c680
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/Framework/Handler/ExceptionsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public function handleError($level, $message, $file = '', $line = 0)
$this->record($error);
if ($this->container->runningInConsole()) {
$this->renderForConsole($error);
} else {
}

if (!$this->container->runningInConsole()) {
$this->renderHttpResponse($error);
}
break;
Expand All @@ -82,14 +84,14 @@ public function handleError($level, $message, $file = '', $line = 0)
return false;
}

public function handleException($e)
public function handleException($exception)
{
$error = [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
'type' => $e->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
'type' => $exception->getCode(),
];

if ($this->isFatal($error['type'])) {
Expand Down Expand Up @@ -149,31 +151,31 @@ protected function renderHttpResponse($e)
*/
public function handleShutdown()
{
if ($e = error_get_last()) {
if ($this->isFatal($e['type'])) {
$this->record($e);
$e['trace'] = '';
if ($exception = error_get_last()) {
if ($this->isFatal($exception['type'])) {
$this->record($exception);
$exception['trace'] = '';
if ($this->container->runningInConsole()) {
$this->renderForConsole($e);
$this->renderForConsole($exception);
}

if (!$this->container->runningInConsole()) {
$this->renderHttpResponse($e);
$this->renderHttpResponse($exception);
}
}
}
}

protected function record($e, $type = 'error', $context = array())
protected function record($exception, $type = 'error', $context = array())
{
$env = $this->container['env'];
$node = $this->container['name'];
$body = 'App Env: 【' . $env . '】, node: 【' . $node . '】 <br> [ Exception ' . $e['message'] . '[' . $e['file'] . ' : ' . $e['line'] . ']';
$body = 'App Env: 【' . $env . '】, node: 【' . $node . '】 <br> [ Exception ' . $exception['message'] . '[' . $exception['file'] . ' : ' . $exception['line'] . ']';

if (($this->container['swift.mail.enabled'] == 'on') && (!$this->container['debug'])) {
$this->container['eventDispatcher']->dispatch(MailEvent::MAIlSEND, new MailEvent($body));
}
\Logger::$type('[' . $this->levels[$e['type']] . '] ' . $e['message'] . '[' . $e['file'] . ' : ' . $e['line'] . ']', $context);
\Logger::$type('[' . $this->levels[$exception['type']] . '] ' . $exception['message'] . '[' . $exception['file'] . ' : ' . $exception['line'] . ']', $context);
}

/**
Expand Down

0 comments on commit bc1c680

Please sign in to comment.