Completed
Pull Request — master (#8)
by Yann
03:17
created

IS2CreditTransfer::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 9
nc 2
nop 8
crap 3

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
     * @throws \InvalidArgumentException. An InvalidArgumentException is thrown if amount is not EUR or CHF
40
     */
41 3
    public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal)
42
    {
43 3
        if (false === $amount instanceof Money\EUR && false === $amount instanceof Money\CHF) {
44 1
            throw new \InvalidArgumentException(sprintf(
45 1
                'Amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF. Instance of %s given.',
46 1
                get_class($amount)
47 1
            ));
48
        }
49
50 2
        parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress);
51
52 2
        $this->creditorIBAN = $creditorIBAN;
53 2
        $this->creditorAgentName = (string) $creditorAgentName;
54 2
        $this->creditorAgentPostal = $creditorAgentPostal;
55 2
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
61
    {
62 2
        $root = $this->buildHeader($doc, $paymentInformation, 'CH03');
63
64 2
        $creditorAgent = $doc->createElement('CdtrAgt');
65 2
        $creditorAgentId = $doc->createElement('FinInstnId');
66 2
        $creditorAgentId->appendChild($doc->createElement('Nm', $this->creditorAgentName));
67 2
        $creditorAgentIdOther = $doc->createElement('Othr');
68 2
        $creditorAgentIdOther->appendChild($doc->createElement('Id', $this->creditorAgentPostal->format()));
69 2
        $creditorAgentId->appendChild($creditorAgentIdOther);
70 2
        $creditorAgent->appendChild($creditorAgentId);
71 2
        $root->appendChild($creditorAgent);
72
73 2
        $root->appendChild($this->buildCreditor($doc));
74
75 2
        $creditorAccount = $doc->createElement('CdtrAcct');
76 2
        $creditorAccount->appendChild($this->creditorIBAN->asDom($doc));
77 2
        $root->appendChild($creditorAccount);
78
79 2
        if ($this->hasRemittanceInformation()) {
80
            $root->appendChild($this->buildRemittanceInformation($doc));
81
        }
82
83 2
        return $root;
84
    }
85
}
86