Completed
Push — master ( 6bf385...7dc2a6 )
by z38
13:00 queued 02:55
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 InvalidArgumentException;
7
use Z38\SwissPayment\IBAN;
8
use Z38\SwissPayment\Money;
9
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
10
use Z38\SwissPayment\PostalAccount;
11
use Z38\SwissPayment\PostalAddressInterface;
12
13
/**
14
 * IS2CreditTransfer contains all the information about a IS 2-stage (type 2.2) transaction.
15
 */
16
class IS2CreditTransfer extends CreditTransfer
17
{
18
    /**
19
     * @var IBAN
20
     */
21
    protected $creditorIBAN;
22
23
    /**
24
     * @var string
25
     */
26
    protected $creditorAgentName;
27
28
    /**
29
     * @var PostalAccount
30
     */
31
    protected $creditorAgentPostal;
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @param IBAN          $creditorIBAN        IBAN of the creditor
37
     * @param string        $creditorAgentName   Name of the creditor's financial institution
38
     * @param PostalAccount $creditorAgentPostal Postal account of the creditor's financial institution
39
     *
40
     * @throws \InvalidArgumentException When the amount is not in EUR or CHF.
41
     */
42 3
    public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal)
43
    {
44 3
        if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) {
45 1
            throw new InvalidArgumentException(sprintf(
46 1
                'The amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF (instance of %s given).',
47 1
                get_class($amount)
48 1
            ));
49
        }
50
51 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
52
53 2
        $this->creditorIBAN = $creditorIBAN;
54 2
        $this->creditorAgentName = (string) $creditorAgentName;
55 2
        $this->creditorAgentPostal = $creditorAgentPostal;
56 2
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
62
    {
63 2
        $root = $this->buildHeader($doc, $paymentInformation, 'CH03');
64
65 2
        $creditorAgent = $doc->createElement('CdtrAgt');
66 2
        $creditorAgentId = $doc->createElement('FinInstnId');
67 2
        $creditorAgentId->appendChild($doc->createElement('Nm', $this->creditorAgentName));
68 2
        $creditorAgentIdOther = $doc->createElement('Othr');
69 2
        $creditorAgentIdOther->appendChild($doc->createElement('Id', $this->creditorAgentPostal->format()));
70 2
        $creditorAgentId->appendChild($creditorAgentIdOther);
71 2
        $creditorAgent->appendChild($creditorAgentId);
72 2
        $root->appendChild($creditorAgent);
73
74 2
        $root->appendChild($this->buildCreditor($doc));
75
76 2
        $creditorAccount = $doc->createElement('CdtrAcct');
77 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
78 2
        $root->appendChild($creditorAccount);
79
80 2
        if ($this->hasRemittanceInformation()) {
81
            $root->appendChild($this->buildRemittanceInformation($doc));
82
        }
83
84 2
        return $root;
85
    }
86
}
87