Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
VerifactuController
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 respond
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 async
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 audit
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5use Psr\Http\Message\ResponseInterface as Response;
6use Psr\Http\Message\ServerRequestInterface as Request;
7use UppServices\VerifactuService;
8
9/**
10 * Slim controller for VeriFactu async and audit-retry endpoints.
11 */
12class VerifactuController
13{
14    private readonly VerifactuService $verifactuService;
15
16    public function __construct(VerifactuService $verifactuService)
17    {
18        $this->verifactuService = $verifactuService;
19    }
20
21    private function respond(Response $response, array $result): Response
22    {
23        $response->getBody()->write($result['output']);
24        return $response->withHeader('Content-Type', $result['contentType']);
25    }
26
27    /** POST /verifactu/async - schedule async VeriFactu update processing. */
28    public function async(Request $request, Response $response): Response
29    {
30        $rawBody = (string) $request->getBody();
31        return $this->respond($response, $this->verifactuService->async($rawBody));
32    }
33
34    /** GET /verifactu/audit — retry pending VeriFactu for a closed audit period. */
35    public function audit(Request $request, Response $response): Response
36    {
37        $out = $this->verifactuService->audit($request->getQueryParams());
38        $response->getBody()->write(json_encode($out));
39
40        return $response->withHeader('Content-Type', 'application/json');
41    }
42}