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

SEPACreditTransfer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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