Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
CodeClimate based cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nik Barham committed Sep 8, 2017
1 parent 934297f commit 452ebf6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Exception/BadRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct($message, $context = null, \Throwable $previous = nu
{
parent::__construct($message, $context, $previous, 400);
}
}
}
3 changes: 2 additions & 1 deletion src/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Circuit\Exception;

use Circuit\Interfaces\ExceptionContextInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -37,4 +38,4 @@ public function setHeaders($header, $value)
{
$this->headers[$header] = $value;
}
}
}
2 changes: 1 addition & 1 deletion src/Exception/Forbidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct($message, $context = null, \Throwable $previous = nu
{
parent::__construct($message, $context, $previous, 403);
}
}
}
2 changes: 1 addition & 1 deletion src/Exception/Gone.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct($message, $context = null, \Throwable $previous = nu
{
parent::__construct($message, $context, $previous, 410);
}
}
}
2 changes: 1 addition & 1 deletion src/Exception/MethodNotAllowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public function __construct(array $allowed, $message, $context = null, \Throwabl
parent::__construct($message, $context, $previous, 405);
$this->setHeaders('Allow', strtoupper(implode(', ', $allowed)));
}
}
}
2 changes: 1 addition & 1 deletion src/Exception/NotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct($message, $context = null, \Throwable $previous = nu
{
parent::__construct($message, $context, $previous, 404);
}
}
}
2 changes: 1 addition & 1 deletion src/Exception/UncaughtException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public function __construct(\Throwable $previous)
{
parent::__construct('Uncaught Exception', null, $previous, 500);
}
}
}
8 changes: 7 additions & 1 deletion src/ExceptionHandler/DefaultHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

class DefaultHandler implements ExceptionHandler
{
public function handle(Exception $e, Request $request, $context) : Response
public function handle(Exception $e, Request $request) : Response
{
if (in_array('application/json', $request->getAcceptableContentTypes())) {
return new JsonResponse(
['error' => $e->getStatusCode() . ' ' . Response::$statusTexts[$e->getStatusCode()] ],
$e->getStatusCode()
);
}
return new Response(
$e->getStatusCode() . ' ' . Response::$statusTexts[$e->getStatusCode()],
$e->getStatusCode(),
Expand Down
11 changes: 9 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,19 @@ public function process(Request $request) : Response

case Dispatcher::METHOD_NOT_ALLOWED:
$this->log("Router: Method not Allowed");
throw new Exception\MethodNotAllowed($dispatch[1], 'Router: Method not Allowed: ' . $request->getMethod());
throw new Exception\MethodNotAllowed(
$dispatch[1],
'Router: Method not Allowed: ' . $request->getMethod()
);

case Dispatcher::FOUND:
try {
$dispatcher = unserialize($dispatch[1]);
$this->log("Router: Route matched: %s@%s", $dispatcher->controllerClass, $dispatcher->controllerMethod);
$this->log(
"Router: Route matched: %s@%s",
$dispatcher->controllerClass,
$dispatcher->controllerMethod
);
return $dispatcher->startProcessing($this, $request, $dispatch[2]);
} catch (\Throwable $e) {
return $this->handleException($e, $request);
Expand Down

0 comments on commit 452ebf6

Please sign in to comment.