Completed
Push — master ( 83472f...6fbcb0 )
by Adelar
02:23
created

AbstractParser::parseXml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
namespace Adelarcubs\OFXParser;
4
5
use SimpleXMLElement;
6
use DateTime;
7
8
/**
9
 *
10
 * @author Adelar Tiemann Junior <[email protected]>
11
 */
12
abstract class AbstractParser
13
{
14
15
    protected $type;
16
17
    protected $document;
18
19
    protected $description;
20
21
    protected $amount;
22
23
    protected $dueDate;
24
25
    public function parseXml(SimpleXMLElement $xml): OfxMovement
26
    {
27
        $this->type = (string) $xml->TRNTYPE;
28
        $this->document = (string) $xml->FITID;
29
        $this->description = (string) $xml->MEMO;
30
        $this->amount = (string) $xml->TRNAMT;
31
        $this->dueDate = (string) $xml->DTPOSTED;
32
33
        return new OfxMovement($this->extractType(), $this->extractDocument(), $this->extractDescription(), $this->extractAmount(), $this->extractDueDate());
34
    }
35
36
    abstract protected function extractType(): string;
37
38
    abstract protected function extractDocument(): string;
39
40
    abstract protected function extractDescription(): string;
41
42
    abstract protected function extractAmount(): float;
43
44
    abstract protected function extractDueDate(): DateTime;
45
}
46