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
TicketsiiController
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
 audit
100.00% covered (success)
100.00%
3 / 3
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
1<?php
2
3declare(strict_types=1);
4
5use Psr\Http\Message\ResponseInterface as Response;
6use Psr\Http\Message\ServerRequestInterface as Request;
7use UppServices\TicketsiiService;
8
9/**
10 * Endpoints TicketSII (SII AEAT).
11 */
12class TicketsiiController
13{
14    public function __construct(private readonly TicketsiiService $ticketsiiService)
15    {
16    }
17
18    private function respond(Response $response, array $result): Response
19    {
20        $response->getBody()->write($result['output']);
21
22        return $response->withHeader('Content-Type', $result['contentType']);
23    }
24
25    /** GET /ticketsii/audit — mismo contrato que el antiguo GET /sii/audit. */
26    public function audit(Request $request, Response $response): Response
27    {
28        $out = $this->ticketsiiService->audit($request->getQueryParams());
29        $response->getBody()->write(json_encode($out));
30
31        return $response->withHeader('Content-Type', 'application/json');
32    }
33
34    /** POST /ticketsii/async — envío en segundo plano con logs TICKETSII. */
35    public function async(Request $request, Response $response): Response
36    {
37        $rawBody = (string) $request->getBody();
38
39        return $this->respond($response, $this->ticketsiiService->async($rawBody));
40    }
41}