Passed
Push — master ( a8e753...d3e13e )
by Carlos C
05:06 queued 03:16
created

CancelSigner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Helpers;
6
7
use DateTimeImmutable;
8
use PhpCfdi\Credentials\Credential;
9
use PhpCfdi\XmlCancelacion\Credentials as XmlCancelacionCredentials;
10
use PhpCfdi\XmlCancelacion\XmlCancelacionHelper;
11
12
class CancelSigner
13
{
14
    /** @var array<string> */
15
    private $uuids;
16
17
    /** @var DateTimeImmutable */
18
    private $dateTime;
19
20
    /**
21
     * CancelSigner constructor
22
     *
23
     * @param array<string> $uuid
24
     * @param DateTimeImmutable|null $dateTime If null or ommited then use current time and time zone
25
     */
26 3
    public function __construct(array $uuid, ?DateTimeImmutable $dateTime = null)
27
    {
28 3
        $this->uuids = $uuid;
29 3
        $this->dateTime = $dateTime ?? new DateTimeImmutable();
30 3
    }
31
32
    /** @return array<string> */
33 3
    public function uuids(): array
34
    {
35 3
        return $this->uuids;
36
    }
37
38 3
    public function dateTime(): DateTimeImmutable
39
    {
40 3
        return $this->dateTime;
41
    }
42
43 2
    public function sign(Credential $credential): string
44
    {
45 2
        $helper = new XmlCancelacionHelper(XmlCancelacionCredentials::createWithPhpCfdiCredential($credential));
46 2
        return $helper->signCancellationUuids($this->uuids(), $this->dateTime());
47
    }
48
49 1
    public function signRetention(Credential $credential): string
50
    {
51 1
        $helper = new XmlCancelacionHelper(XmlCancelacionCredentials::createWithPhpCfdiCredential($credential));
52 1
        return $helper->signRetentionCancellationUuids($this->uuids(), $this->dateTime());
53
    }
54
}
55