Completed
Push — master ( 6bf385...7dc2a6 )
by z38
13:00 queued 02:55
created

SEPACreditTransfer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.3%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 1
cbo 3
dl 0
loc 56
ccs 21
cts 23
cp 0.913
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A asDom() 0 22 3
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
39 2
        if ($creditorAgentBIC !== null) {
40 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...
41 2
            $this->creditorAgentBIC = $creditorAgentBIC;
42 2
        }
43 2
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
49
    {
50 2
        $root = $this->buildHeader($doc, $paymentInformation, null, 'SEPA');
51
52 2
        if ($this->creditorAgentBIC !== null) {
53 2
            $creditorAgent = $doc->createElement('CdtrAgt');
54 2
            $creditorAgent->appendChild($this->creditorAgentBIC->asDom($doc));
55 2
            $root->appendChild($creditorAgent);
56 2
        }
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