Completed
Push — feature-purposes ( ae1ada )
by z38
02:44
created

SEPACreditTransfer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 57
ccs 23
cts 23
cp 1
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A asDom() 0 22 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 asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
50
    {
51 2
        $root = $this->buildHeader($doc, $paymentInformation);
52
53 2
        if ($this->creditorAgentBIC !== null) {
54 2
            $creditorAgent = $doc->createElement('CdtrAgt');
55 2
            $creditorAgent->appendChild($this->creditorAgentBIC->asDom($doc));
56 2
            $root->appendChild($creditorAgent);
57 2
        }
58
59 2
        $root->appendChild($this->buildCreditor($doc));
60
61 2
        $creditorAccount = $doc->createElement('CdtrAcct');
62 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
63 2
        $root->appendChild($creditorAccount);
64
65 2
        $this->appendPurpose($doc, $root);
66
67 2
        $this->appendRemittanceInformation($doc, $root);
68
69 2
        return $root;
70
    }
71
}
72