Passed
Pull Request — master (#16)
by Carlos C
02:51
created

CancelSigner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 78.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 41
ccs 11
cts 14
cp 0.7856
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A dateTime() 0 3 1
A sign() 0 4 1
A uuids() 0 3 1
A signRetention() 0 4 1
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 1
    public function __construct(array $uuid, ?DateTimeImmutable $dateTime = null)
27
    {
28 1
        $this->uuids = $uuid;
29 1
        $this->dateTime = $dateTime ?? new DateTimeImmutable();
30 1
    }
31
32
    /** @return array<string> */
33 1
    public function uuids(): array
34
    {
35 1
        return $this->uuids;
36
    }
37
38 1
    public function dateTime(): DateTimeImmutable
39
    {
40 1
        return $this->dateTime;
41
    }
42
43 1
    public function sign(Credential $credential): string
44
    {
45 1
        $helper = new XmlCancelacionHelper(XmlCancelacionCredentials::createWithPhpCfdiCredential($credential));
46 1
        return $helper->signCancellationUuids($this->uuids(), $this->dateTime());
47
    }
48
49
    public function signRetention(Credential $credential): string
50
    {
51
        $helper = new XmlCancelacionHelper(XmlCancelacionCredentials::createWithPhpCfdiCredential($credential));
52
        return $helper->signRetentionCancellationUuids($this->uuids(), $this->dateTime());
53
    }
54
}
55