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

SEPACreditTransfer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 7
crap 1
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use DOMDocument;
6
use Z38\SwissPayment\BIC;
7
use Z38\SwissPayment\IBAN;
8
use Z38\SwissPayment\Money;
9
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * SEPACreditTransfer contains all the information about a foreign SEPA (type 5) transaction.
14
 */
15
class SEPACreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var IBAN
19
     */
20
    protected $creditorIBAN;
21
22
    /**
23
     * @var BIC
24
     */
25
    protected $creditorAgentBIC;
26
27
    /**
28
     * {@inheritdoc}
29
     *
30
     * @param IBAN $creditorIBAN     IBAN of the creditor
31
     * @param BIC  $creditorAgentBIC BIC of the creditor's financial institution
32
     */
33 2
    public function __construct($instructionId, $endToEndId, Money\EUR $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, BIC $creditorAgentBIC)
34
    {
35 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
36
37 2
        $this->creditorIBAN = $creditorIBAN;
38 2
        $this->creditorAgentBIC = $creditorAgentBIC;
39 2
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
45
    {
46 2
        $root = $this->buildHeader($doc, $paymentInformation, null, 'SEPA');
47
48 2
        $creditorAgent = $doc->createElement('CdtrAgt');
49
50 2
        $creditorAgent->appendChild($this->creditorAgentBIC->asDom($doc));
51 2
        $root->appendChild($creditorAgent);
52
53 2
        $root->appendChild($this->buildCreditor($doc));
54
55 2
        $creditorAccount = $doc->createElement('CdtrAcct');
56 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
57 2
        $root->appendChild($creditorAccount);
58
59 2
        if ($this->hasRemittanceInformation()) {
60
            $root->appendChild($this->buildRemittanceInformation($doc));
61
        }
62
63 2
        return $root;
64
    }
65
}
66