Passed
Push — main ( f66402...3f489b )
by Carlos C
02:36 queued 11s
created

CancelSigner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A dateTime() 0 3 1
A sign() 0 4 1
A __construct() 0 4 1
A signRetention() 0 4 1
A documents() 0 3 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\Models\CancelDocuments;
11
use PhpCfdi\XmlCancelacion\XmlCancelacionHelper;
12
13
class CancelSigner
14
{
15
    /** @var CancelDocuments*/
16
    private $documents;
17
18
    /** @var DateTimeImmutable */
19
    private $dateTime;
20
21
    /**
22
     * CancelSigner constructor
23
     *
24
     * @param CancelDocuments $documents
25
     * @param DateTimeImmutable|null $dateTime If null or ommited then use current time and time zone
26
     */
27 3
    public function __construct(CancelDocuments $documents, ?DateTimeImmutable $dateTime = null)
28
    {
29 3
        $this->documents = $documents;
30 3
        $this->dateTime = $dateTime ?? new DateTimeImmutable();
31 3
    }
32
33
    /** @return CancelDocuments */
34 3
    public function documents(): CancelDocuments
35
    {
36 3
        return $this->documents;
37
    }
38
39 3
    public function dateTime(): DateTimeImmutable
40
    {
41 3
        return $this->dateTime;
42
    }
43
44 2
    public function sign(Credential $credential): string
45
    {
46 2
        $helper = new XmlCancelacionHelper(XmlCancelacionCredentials::createWithPhpCfdiCredential($credential));
47 2
        return $helper->signCancellationUuids($this->documents(), $this->dateTime());
48
    }
49
50 1
    public function signRetention(Credential $credential): string
51
    {
52 1
        $helper = new XmlCancelacionHelper(XmlCancelacionCredentials::createWithPhpCfdiCredential($credential));
53 1
        return $helper->signRetentionCancellationUuids($this->documents(), $this->dateTime());
54
    }
55
}
56