ApiAuthorizationController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A authorization() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller;
6
7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
final class ApiAuthorizationController extends AbstractController
13
{
14
    private $integrationApiKey;
15
16
    public function __construct(string $integrationApiKey)
17
    {
18
        $this->integrationApiKey = $integrationApiKey;
19
    }
20
21
    public function authorization(Request $request): Response
22
    {
23
        if ($this->integrationApiKey !== $request->request->get('api_key', $request->headers->get('X-API-KEY'))) {
24
            return new JsonResponse(['success' => false], Response::HTTP_FORBIDDEN);
25
        }
26
27
        return new JsonResponse(['success' => true]);
28
    }
29
}
30