Completed
Pull Request — master (#6)
by
unknown
03:15
created

SEPACreditTransfer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 76%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 4
dl 0
loc 58
ccs 19
cts 25
cp 0.76
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B asDom() 0 27 3
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use Z38\SwissPayment\BIC;
6
use Z38\SwissPayment\IBAN;
7
use Z38\SwissPayment\Money;
8
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
9
use Z38\SwissPayment\PostalAddressInterface;
10
11
/**
12
 * SEPACreditTransfer contains all the information about a foreign SEPA (type 5) transaction.
13
 */
14
class SEPACreditTransfer extends CreditTransfer
15
{
16
    /**
17
     * @var IBAN
18
     */
19
    protected $creditorIBAN;
20
21
    /**
22
     * @var BIC
23
     */
24
    protected $creditorAgentBIC;
25
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @param IBAN $creditorIBAN     IBAN of the creditor
30
     * @param BIC  $creditorAgentBIC BIC of the creditor's financial institution
31
     * @param IntermediarySwift $intermediarySwift
32
     */
33 3
    public function __construct($instructionId, $endToEndId, Money\EUR $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, BIC $creditorAgentBIC, $intermediarySwift = null)
34
    {
35 3
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress, $intermediarySwift);
36
37 3
        $this->creditorIBAN = $creditorIBAN;
38 3
        $this->creditorAgentBIC = $creditorAgentBIC;
39 3
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function asDom(\DOMDocument $doc, PaymentInformation $paymentInformation)
45
    {
46 2
        $root = $this->buildHeader($doc, $paymentInformation, null, 'SEPA');
47
48 2
        $creditorAgent = $doc->createElement('CdtrAgt');
49 2
        $creditorAgent->appendChild($this->creditorAgentBIC->asDom($doc));
50 2
        $root->appendChild($creditorAgent);
51 2
        $root->appendChild($this->buildCreditor($doc));
52
53 2
        if ($this->intermediarySwift) {
54
            $intermediary = $doc->createElement('IntrmyAgt1');
55
            $intermediary->appendChild($this->intermediarySwift->asDom($doc));
56
            $root->appendChild($intermediary);
57
        }
58
59 2
        $creditorAccount = $doc->createElement('CdtrAcct');
60 2
        $creditorAccountId = $doc->createElement('Id');
61 2
        $creditorAccountId->appendChild($doc->createElement('IBAN', $this->creditorIBAN->normalize()));
62 2
        $creditorAccount->appendChild($creditorAccountId);
63 2
        $root->appendChild($creditorAccount);
64
65 2
        if ($this->hasRemittanceInformation()) {
66
            $root->appendChild($this->buildRemittanceInformation($doc));
67
        }
68
69 2
        return $root;
70
    }
71
}
72