Passed
Push — master ( 77290b...f3fb78 )
by Marcel
09:09
created

IdpExchangeController::parseAndValidateRequestOrThrowError()   A

Complexity

Conditions 4
Paths 10

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 10
nop 2
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 20
rs 9.9
1
<?php
2
3
namespace App\Controller\Api;
4
5
use App\Entity\Application;
6
use App\Service\IdpExchangeService;
7
use Psr\Log\LoggerInterface;
8
use SchulIT\IdpExchange\Request\UpdatedUsersRequest;
9
use SchulIT\IdpExchange\Request\UserRequest;
10
use SchulIT\IdpExchange\Request\UsersRequest;
11
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use Symfony\Component\Routing\Annotation\Route;
15
use Symfony\Component\Validator\Validator\ValidatorInterface;
16
17
#[Route(path: '/exchange')]
18
class IdpExchangeController extends AbstractController {
19
20
    public function __construct(private readonly IdpExchangeService $service) { }
21
22
    /**
23
     * Default IdP Exchange controller (only used for testing purporses)
24
     */
25
    #[Route(path: '', name: 'idp_exchange_default')]
26
    public function index(): Response {
27
        return $this->json([]);
28
    }
29
30
    #[Route(path: '/updated_users', name: 'idp_exchange_updated_users', methods: ['POST'])]
31
    public function updatedUsers(UpdatedUsersRequest $exchangeRequest): Response {
32
        $response = $this->service->getUpdatedUsers($exchangeRequest);
33
        return $this->json($response);
34
    }
35
36
    #[Route(path: '/users', name: 'idp_exchange_users', methods: ['POST'])]
37
    public function users(UsersRequest $exchangeRequest): Response {
38
        /** @var Application $application */
39
        $application = $this->getUser();
40
41
        $response = $this->service->getUsers($exchangeRequest, $application->getService()->getEntityId());
42
        return $this->json($response);
43
    }
44
45
    #[Route(path: '/user', name: 'idp_exchange_user', methods: ['POST'])]
46
    public function user(UserRequest $exchangeRequest): Response {
47
        /** @var Application $application */
48
        $application = $this->getUser();
49
50
        $response = $this->service->getUser($exchangeRequest, $application->getService()->getEntityId());
51
        return $this->json($response);
52
    }
53
}