Completed
Push — master ( dc2855...0a5beb )
by z38
03:37
created

IS2CreditTransfer::asDom()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0054

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 25
ccs 16
cts 18
cp 0.8889
rs 8.8571
cc 2
eloc 17
nc 2
nop 2
crap 2.0054
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use DOMDocument;
6
use Z38\SwissPayment\IBAN;
7
use Z38\SwissPayment\Money;
8
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
9
use Z38\SwissPayment\PostalAccount;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * IS2CreditTransfer contains all the information about a IS 2-stage (type 2.2) transaction.
14
 */
15
class IS2CreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var IBAN
19
     */
20
    protected $creditorIBAN;
21
22
    /**
23
     * @var string
24
     */
25
    protected $creditorAgentName;
26
27
    /**
28
     * @var PostalAccount
29
     */
30
    protected $creditorAgentPostal;
31
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * @param IBAN          $creditorIBAN        IBAN of the creditor
36
     * @param string        $creditorAgentName   Name of the creditor's financial institution
37
     * @param PostalAccount $creditorAgentPostal Postal account of the creditor's financial institution
38
     */
39 2
    public function __construct($instructionId, $endToEndId, Money\CHF $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal)
40
    {
41 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
42
43 2
        $this->creditorIBAN = $creditorIBAN;
44 2
        $this->creditorAgentName = (string) $creditorAgentName;
45 2
        $this->creditorAgentPostal = $creditorAgentPostal;
46 2
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
52
    {
53 2
        $root = $this->buildHeader($doc, $paymentInformation, 'CH03');
54
55 2
        $creditorAgent = $doc->createElement('CdtrAgt');
56 2
        $creditorAgentId = $doc->createElement('FinInstnId');
57 2
        $creditorAgentId->appendChild($doc->createElement('Nm', $this->creditorAgentName));
58 2
        $creditorAgentIdOther = $doc->createElement('Othr');
59 2
        $creditorAgentIdOther->appendChild($doc->createElement('Id', $this->creditorAgentPostal->format()));
60 2
        $creditorAgentId->appendChild($creditorAgentIdOther);
61 2
        $creditorAgent->appendChild($creditorAgentId);
62 2
        $root->appendChild($creditorAgent);
63
64 2
        $root->appendChild($this->buildCreditor($doc));
65
66 2
        $creditorAccount = $doc->createElement('CdtrAcct');
67 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
68 2
        $root->appendChild($creditorAccount);
69
70 2
        if ($this->hasRemittanceInformation()) {
71
            $root->appendChild($this->buildRemittanceInformation($doc));
72
        }
73
74 2
        return $root;
75
    }
76
}
77