Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TicketsiiService
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
8
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
 audit
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
 async
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace UppServices;
6
7require_once __DIR__.'/legacy/ddbb/conx.php';
8require_once __DIR__.'/ticketsii/sendsii.php';
9
10/**
11 * TicketSII (SII AEAT): auditoría y envío asíncrono.
12 */
13class TicketsiiService
14{
15    private const TICKETSII_ACTIONS_DIR = __DIR__.'/ticketsii';
16
17    private readonly LoggerFactory $loggerFactory;
18
19    /** @var callable|null */
20    private static $asyncAction = null;
21
22    public function __construct(LoggerFactory $loggerFactory)
23    {
24        $this->loggerFactory = $loggerFactory;
25    }
26
27    /**
28     * GET /ticketsii/audit (y alias GET /sii/audit).
29     *
30     * @param array<string, string|int|float|null> $query
31     * @return array{errorcode: int, ticketsok: mixed, ticketsko: mixed}
32     */
33    public function audit(array $query): array
34    {
35        $device = isset($query['device']) ? (string) $query['device'] : '';
36        $session = isset($query['session']) ? (string) $query['session'] : '';
37        $place = isset($query['place']) ? (string) $query['place'] : '';
38        $audit = isset($query['audit']) ? (string) $query['audit'] : '';
39
40        $conx = new \ConxHelper(__FILE__);
41        try {
42            return sendsii_run($conx, $device, $session, $place, $audit);
43        } finally {
44            $conx->release();
45        }
46    }
47
48    /**
49     * POST /ticketsii/async.
50     *
51     * @return array{output: string, contentType: string}
52     */
53    public function async(string $rawBody): array
54    {
55        $conx = new \ConxHelper(__FILE__);
56        if (self::$asyncAction === null) {
57            self::$asyncAction = require_once self::TICKETSII_ACTIONS_DIR.'/AsyncSend.php';
58        }
59        $action = self::$asyncAction;
60        $logger = $this->loggerFactory->for(__FILE__);
61        try {
62            return $action($rawBody, $conx, $logger);
63        } finally {
64            $conx->release();
65        }
66    }
67}