Completed
Push — master ( 6bf385...7dc2a6 )
by z38
13:00 queued 02:55
created

IS1CreditTransfer::asDom()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.032

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 16
ccs 8
cts 10
cp 0.8
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2.032
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use DOMDocument;
6
use InvalidArgumentException;
7
use Z38\SwissPayment\Money;
8
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
9
use Z38\SwissPayment\PostalAccount;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * IS1CreditTransfer contains all the information about a IS 1-stage (type 2.1) transaction.
14
 */
15
class IS1CreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var PostalAccount
19
     */
20
    protected $creditorAccount;
21
22
    /**
23
     * {@inheritdoc}
24
     *
25
     * @param PostalAccount $creditorAccount Postal account of the creditor
26
     *
27
     * @throws \InvalidArgumentException When the amount is not in EUR or CHF.
28
     */
29 3
    public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, PostalAccount $creditorAccount)
30
    {
31 3
        if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) {
32 1
            throw new InvalidArgumentException(sprintf(
33 1
                'The amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF (instance of %s given).',
34 1
                get_class($amount)
35 1
            ));
36
        }
37
38 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
39
40 2
        $this->creditorAccount = $creditorAccount;
41 2
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
47
    {
48 2
        $root = $this->buildHeader($doc, $paymentInformation, 'CH02');
49
50 2
        $root->appendChild($this->buildCreditor($doc));
51
52 2
        $creditorAccount = $doc->createElement('CdtrAcct');
53 2
        $creditorAccount->appendChild($this->creditorAccount->asDom($doc));
54 2
        $root->appendChild($creditorAccount);
55
56 2
        if ($this->hasRemittanceInformation()) {
57
            $root->appendChild($this->buildRemittanceInformation($doc));
58
        }
59
60 2
        return $root;
61
    }
62
}
63