Completed
Pull Request — master (#9)
by Carlos C
03:14
created

GetSatStatusExtractor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXmlDocument() 0 4 1
A __construct() 0 7 1
A buildCommand() 0 4 1
A fromXmlString() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Helpers;
6
7
use DOMDocument;
8
use PhpCfdi\CfdiExpresiones\DiscoverExtractor;
9
use PhpCfdi\Finkok\Services\Cancel\GetSatStatusCommand;
10
11
class GetSatStatusExtractor
12
{
13
    /** @var string[] */
14
    private $expressionData;
15
16
    /**
17
     * GetSatStatusExtractor constructor.
18
     *
19
     * @param array $expressionData
20
     */
21 2
    public function __construct(array $expressionData)
22
    {
23 2
        $this->expressionData = [
24 2
            're' => strval($expressionData['re'] ?? ''),
25 2
            'rr' => strval($expressionData['rr'] ?? ''),
26 2
            'tt' => strval($expressionData['tt'] ?? ''),
27 2
            'id' => strval($expressionData['id'] ?? ''),
28
        ];
29 2
    }
30
31 1
    public static function fromXmlDocument(DOMDocument $document)
32
    {
33 1
        $discoverer = new DiscoverExtractor();
34 1
        return new self($discoverer->obtain($document));
35
    }
36
37 1
    public static function fromXmlString(string $xmlCfdi): self
38
    {
39 1
        $document = new DOMDocument();
40 1
        $document->loadXML($xmlCfdi);
41 1
        return static::fromXmlDocument($document);
42
    }
43
44 2
    public function buildCommand(): GetSatStatusCommand
45
    {
46 2
        $expData = $this->expressionData;
47 2
        return new GetSatStatusCommand($expData['re'], $expData['rr'], $expData['id'], $expData['tt']);
48
    }
49
}
50