Completed
Push — master ( dc2855...0a5beb )
by z38
03:37
created

IS2CreditTransfer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
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 DOMDocument;
6
use Z38\SwissPayment\IBAN;
7
use Z38\SwissPayment\Money;
8
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
9
use Z38\SwissPayment\PostalAccount;
10
use Z38\SwissPayment\PostalAddressInterface;
11
12
/**
13
 * IS2CreditTransfer contains all the information about a IS 2-stage (type 2.2) transaction.
14
 */
15
class IS2CreditTransfer extends CreditTransfer
16
{
17
    /**
18
     * @var IBAN
19
     */
20
    protected $creditorIBAN;
21
22
    /**
23
     * @var string
24
     */
25
    protected $creditorAgentName;
26
27
    /**
28
     * @var PostalAccount
29
     */
30
    protected $creditorAgentPostal;
31
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * @param IBAN          $creditorIBAN        IBAN of the creditor
36
     * @param string        $creditorAgentName   Name of the creditor's financial institution
37
     * @param PostalAccount $creditorAgentPostal Postal account of the creditor's financial institution
38
     */
39 2
    public function __construct($instructionId, $endToEndId, Money\CHF $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal)
40
    {
41 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
42
43 2
        $this->creditorIBAN = $creditorIBAN;
44 2
        $this->creditorAgentName = (string) $creditorAgentName;
45 2
        $this->creditorAgentPostal = $creditorAgentPostal;
46 2
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
52
    {
53 2
        $root = $this->buildHeader($doc, $paymentInformation, 'CH03');
54
55 2
        $creditorAgent = $doc->createElement('CdtrAgt');
56 2
        $creditorAgentId = $doc->createElement('FinInstnId');
57 2
        $creditorAgentId->appendChild($doc->createElement('Nm', $this->creditorAgentName));
58 2
        $creditorAgentIdOther = $doc->createElement('Othr');
59 2
        $creditorAgentIdOther->appendChild($doc->createElement('Id', $this->creditorAgentPostal->format()));
60 2
        $creditorAgentId->appendChild($creditorAgentIdOther);
61 2
        $creditorAgent->appendChild($creditorAgentId);
62 2
        $root->appendChild($creditorAgent);
63
64 2
        $root->appendChild($this->buildCreditor($doc));
65
66 2
        $creditorAccount = $doc->createElement('CdtrAcct');
67 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
68 2
        $root->appendChild($creditorAccount);
69
70 2
        if ($this->hasRemittanceInformation()) {
71
            $root->appendChild($this->buildRemittanceInformation($doc));
72
        }
73
74 2
        return $root;
75
    }
76
}
77