Replaced in_array by contains

This commit is contained in:
Alejandro Celaya
2018-10-05 18:52:42 +02:00
parent ebf2e459e8
commit e55dbef2fc
6 changed files with 45 additions and 27 deletions

View File

@@ -9,6 +9,9 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response;
use Zend\Expressive\Template\TemplateRendererInterface;
use function array_shift;
use function explode;
use function Shlinkio\Shlink\Common\contains;
class NotFoundHandler implements RequestHandlerInterface
{
@@ -39,12 +42,12 @@ class NotFoundHandler implements RequestHandlerInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$accepts = \explode(',', $request->getHeaderLine('Accept'));
$accept = \array_shift($accepts);
$accepts = explode(',', $request->getHeaderLine('Accept'));
$accept = array_shift($accepts);
$status = StatusCodeInterface::STATUS_NOT_FOUND;
// If the first accepted type is json, return a json response
if (\in_array($accept, ['application/json', 'text/json', 'application/x-json'], true)) {
if (contains($accept, ['application/json', 'text/json', 'application/x-json'])) {
return new Response\JsonResponse([
'error' => 'NOT_FOUND',
'message' => 'Not found',