Passed
Pull Request — master (#5)
by Carlos C
02:00
created

GetRelatedSigner   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A sign() 0 4 1
A pacRfc() 0 3 1
A __construct() 0 5 2
A uuid() 0 3 1
A role() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Helpers;
6
7
use PhpCfdi\Credentials\Credential;
8
use PhpCfdi\Finkok\Definitions\RfcRole;
9
use PhpCfdi\XmlCancelacion\Credentials;
10
use PhpCfdi\XmlCancelacion\XmlCancelacionHelper;
11
12
class GetRelatedSigner
13
{
14
    public const DEFAULT_PACRFC = 'CVD110412TF6';
15
16
    /** @var string */
17
    private $uuid;
18
19
    /** @var RfcRole */
20
    private $role;
21
22
    /** @var string */
23
    private $pacRfc;
24
25
    /**
26
     * GetRelatedSigner constructor.
27
     *
28
     * @param string $uuid
29
     * @param RfcRole|null $role If null or ommited then uses issuer role
30
     * @param string $pacRfc If empty or ommited then uses DEFAULT_PACRFC
31
     */
32 1
    public function __construct(string $uuid, RfcRole $role = null, string $pacRfc = self::DEFAULT_PACRFC)
33
    {
34 1
        $this->uuid = $uuid;
35 1
        $this->role = $role ?? RfcRole::issuer();
36 1
        $this->pacRfc = $pacRfc ?: static::DEFAULT_PACRFC;
37 1
    }
38
39 1
    public function uuid(): string
40
    {
41 1
        return $this->uuid;
42
    }
43
44 1
    public function role(): RfcRole
45
    {
46 1
        return $this->role;
47
    }
48
49 1
    public function pacRfc(): string
50
    {
51 1
        return $this->pacRfc;
52
    }
53
54 1
    public function sign(Credential $credential): string
55
    {
56 1
        $helper = new XmlCancelacionHelper(Credentials::createWithPhpCfdiCredential($credential));
57 1
        return $helper->signObtainRelated($this->uuid(), $this->role(), $this->pacRfc());
58
    }
59
}
60