IS1CreditTransfer::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

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