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

GetSatStatusExtractor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
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