Completed
Push — wip ( 681ec1 )
by z38
02:37
created

ISRCreditTransfer::appendRemittanceInformation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Z38\SwissPayment\TransactionInformation;
4
5
use DOMDocument;
6
use InvalidArgumentException;
7
use LogicException;
8
use Z38\SwissPayment\ISRParticipant;
9
use Z38\SwissPayment\Money;
10
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
11
use Z38\SwissPayment\RemittanceInformation\ISRReferenceInformation;
12
use Z38\SwissPayment\RemittanceInformation\RemittanceInformation;
13
14
/**
15
 * ISRCreditTransfer contains all the information about a ISR (type 1) transaction.
16
 */
17
class ISRCreditTransfer extends CreditTransfer
18
{
19
    /**
20
     * @var ISRParticipant
21
     */
22
    protected $creditorAccount;
23
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @param ISRParticipant $creditorAccount   ISR participation number of the creditor
28
     * @param string         $creditorReference ISR reference number
29
     *
30
     * @throws InvalidArgumentException When the amount is not in EUR or CHF.
31
     */
32 3
    public function __construct($instructionId, $endToEndId, Money\Money $amount, ISRParticipant $creditorAccount, $creditorReference)
33
    {
34 3
        if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) {
35 1
            throw new InvalidArgumentException(sprintf(
36 1
                'The amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF (instance of %s given).',
37 1
                get_class($amount)
38 1
            ));
39
        }
40
41 2
        $this->instructionId = (string) $instructionId;
42 2
        $this->endToEndId = (string) $endToEndId;
43 2
        $this->amount = $amount;
44 2
        $this->creditorAccount = $creditorAccount;
45 2
        $this->localInstrument = 'CH01';
46
47 2
        parent::setRemittanceInformation(new ISRReferenceInformation($creditorReference));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setRemittanceInformation() instead of __construct()). Are you sure this is correct? If so, you might want to change this to $this->setRemittanceInformation().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
48 2
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function setRemittanceInformation(RemittanceInformation $remittanceInformation)
54
    {
55 1
        throw new LogicException('ISR payments are not able to store additional remittance information.');
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 2
    public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
62
    {
63 2
        $root = $this->buildHeader($doc, $paymentInformation);
64
65 2
        $creditorAccount = $doc->createElement('CdtrAcct');
66 2
        $creditorAccount->appendChild($this->creditorAccount->asDom($doc));
67 2
        $root->appendChild($creditorAccount);
68
69 2
        $this->appendPurpose($doc, $root);
70
71 2
        $this->appendRemittanceInformation($doc, $root);
72
73 2
        return $root;
74
    }
75
}
76