Completed
Push — master ( 39872e...0a5beb )
by z38
09:00 queued 02:22
created

BankCreditTransfer::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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