Completed
Push — wip ( 681ec1 )
by z38
02:37
created

SEPACreditTransfer::asDom()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 22
ccs 14
cts 14
cp 1
rs 9.2
c 1
b 0
f 0
cc 2
eloc 13
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use DOMDocument;
6
use Z38\SwissPayment\BIC;
7
use Z38\SwissPayment\IBAN;
8
use Z38\SwissPayment\Money;
9
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * SEPACreditTransfer contains all the information about a foreign SEPA (type 5) transaction.
14
 */
15
class SEPACreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var IBAN
19
     */
20
    protected $creditorIBAN;
21
22
    /**
23
     * @var BIC|null
24
     */
25
    protected $creditorAgentBIC;
26
27
    /**
28
     * {@inheritdoc}
29
     *
30
     * @param IBAN     $creditorIBAN     IBAN of the creditor
31
     * @param BIC|null $creditorAgentBIC BIC of the creditor's financial institution
32
     */
33 2
    public function __construct($instructionId, $endToEndId, Money\EUR $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, BIC $creditorAgentBIC = null)
34
    {
35 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
36
37 2
        $this->creditorIBAN = $creditorIBAN;
38 2
        $this->serviceLevel = 'SEPA';
39
40 2
        if ($creditorAgentBIC !== null) {
41 2
            @trigger_error('Setting the creditor agent BIC of SEPA payments is deprecated. The execution of the payment will be based on the IBAN.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
42 2
            $this->creditorAgentBIC = $creditorAgentBIC;
43 2
        }
44 2
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 2
    public function getChargeBearer()
50
    {
51 2
        return 'SLEV';
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
58
    {
59 2
        $root = $this->buildHeader($doc, $paymentInformation);
60
61 2
        if ($this->creditorAgentBIC !== null) {
62 2
            $creditorAgent = $doc->createElement('CdtrAgt');
63 2
            $creditorAgent->appendChild($this->creditorAgentBIC->asDom($doc));
64 2
            $root->appendChild($creditorAgent);
65 2
        }
66
67 2
        $root->appendChild($this->buildCreditor($doc));
68
69 2
        $creditorAccount = $doc->createElement('CdtrAcct');
70 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
71 2
        $root->appendChild($creditorAccount);
72
73 2
        $this->appendPurpose($doc, $root);
74
75 2
        $this->appendRemittanceInformation($doc, $root);
76
77 2
        return $root;
78
    }
79
}
80