ForeignCreditTransfer::asDom()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 17
cts 17
cp 1
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use DOMDocument;
6
use Z38\SwissPayment\AccountInterface;
7
use Z38\SwissPayment\BIC;
8
use Z38\SwissPayment\FinancialInstitutionAddress;
9
use Z38\SwissPayment\FinancialInstitutionInterface;
10
use Z38\SwissPayment\Money\Money;
11
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
12
13
/**
14
 * ForeignCreditTransfer contains all the information about a foreign (type 6) transaction.
15
 */
16
class ForeignCreditTransfer extends CreditTransfer
17
{
18
    /**
19
     * @var AccountInterface
20
     */
21
    protected $creditorAccount;
22
23
    /**
24
     * @var BIC|FinancialInstitutionAddress
25
     */
26
    protected $creditorAgent;
27
28
    /**
29
     * @var BIC
30
     */
31
    protected $intermediaryAgent;
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @param AccountInterface                $creditorAccount Account of the creditor
37
     * @param BIC|FinancialInstitutionAddress $creditorAgent   BIC or address of the creditor's financial institution
38
     */
39 4
    public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, $creditorAddress, AccountInterface $creditorAccount, FinancialInstitutionInterface $creditorAgent)
40
    {
41 4
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
42
43 4
        if (!$creditorAgent instanceof BIC && !$creditorAgent instanceof FinancialInstitutionAddress) {
44 1
            throw new \InvalidArgumentException('The creditor agent must be an instance of BIC or FinancialInstitutionAddress.');
45
        }
46
47 3
        $this->creditorAccount = $creditorAccount;
48 3
        $this->creditorAgent = $creditorAgent;
49 3
    }
50
51
    /**
52
     * Set the intermediary agent of the transaction.
53
     *
54
     * @param BIC $intermediaryAgent BIC of the intmediary agent
55
     */
56 3
    public function setIntermediaryAgent(BIC $intermediaryAgent)
57
    {
58 3
        $this->intermediaryAgent = $intermediaryAgent;
59 3
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
65
    {
66 2
        $root = $this->buildHeader($doc, $paymentInformation);
67
68 2
        if ($this->intermediaryAgent !== null) {
69 2
            $intermediaryAgent = $doc->createElement('IntrmyAgt1');
70 2
            $intermediaryAgent->appendChild($this->intermediaryAgent->asDom($doc));
71 2
            $root->appendChild($intermediaryAgent);
72 2
        }
73
74 2
        $creditorAgent = $doc->createElement('CdtrAgt');
75 2
        $creditorAgent->appendChild($this->creditorAgent->asDom($doc));
76 2
        $root->appendChild($creditorAgent);
77
78 2
        $root->appendChild($this->buildCreditor($doc));
79
80 2
        $creditorAccount = $doc->createElement('CdtrAcct');
81 2
        $creditorAccount->appendChild($this->creditorAccount->asDom($doc));
82 2
        $root->appendChild($creditorAccount);
83
84 2
        $this->appendPurpose($doc, $root);
85
86 2
        $this->appendRemittanceInformation($doc, $root);
87
88 2
        return $root;
89
    }
90
}
91