Completed
Push — feature-purposes ( ae1ada )
by z38
02:44
created

IS1CreditTransfer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 49
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A asDom() 0 16 1
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
        $this->localInstrument = 'CH02';
42 2
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
48
    {
49 2
        $root = $this->buildHeader($doc, $paymentInformation);
50
51 2
        $root->appendChild($this->buildCreditor($doc));
52
53 2
        $creditorAccount = $doc->createElement('CdtrAcct');
54 2
        $creditorAccount->appendChild($this->creditorAccount->asDom($doc));
55 2
        $root->appendChild($creditorAccount);
56
57 2
        $this->appendPurpose($doc, $root);
58
59 2
        $this->appendRemittanceInformation($doc, $root);
60
61 2
        return $root;
62
    }
63
}
64