Passed
Pull Request — master (#26)
by Paweł
03:29
created

ApiAuthorizationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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