Completed
Push — master ( 684883...0d5cb2 )
by Frederik
06:17 queued 04:16
created

EntryTransactionDetail::addRelatedParties()   F

Complexity

Conditions 16
Paths 1029

Size

Total Lines 58
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 39
CRAP Score 16.004

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 58
ccs 39
cts 40
cp 0.975
rs 3.2279
cc 16
eloc 38
nc 1029
nop 2
crap 16.004

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Genkgo\Camt\Decoder;
4
5
use Genkgo\Camt\DTO;
6
use \SimpleXMLElement;
7
use Genkgo\Camt\Iban;
8
9
abstract class EntryTransactionDetail
10
{
11
    /**
12
     * @param DTO\EntryTransactionDetail $detail
13
     * @param SimpleXMLElement           $xmlDetail
14
     */
15 15
    public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
16
    {
17 15
        if (false === isset($xmlDetail->Refs)) {
18 1
            return;
19
        }
20
21 14
        $refs = $xmlDetail->Refs;
0 ignored issues
show
Bug introduced by
The property Refs does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
22 15
        $reference = new DTO\Reference();
23
24 14
        $reference->setMessageId(isset($refs->MsgId) ? (string) $refs->MsgId : null);
25 14
        $reference->setAccountServiceReference(isset($refs->AcctSvcrRef) ? (string) $refs->AcctSvcrRef : null);
26 14
        $reference->setPaymentInformationId(isset($refs->PmtInfId) ? (string) $refs->PmtInfId : null);
27 14
        $reference->setInstructionId(isset($refs->InstrId) ? (string) $refs->InstrId : null);
28 14
        $reference->setEndToEndId(isset($refs->EndToEndId) ? (string) $refs->EndToEndId : null);
29 14
        $reference->setTransactionId(isset($refs->TxId) ? (string) $refs->TxId : null);
30 14
        $reference->setMandateId(isset($refs->MndtId) ? (string) $refs->MndtId : null);
31 14
        $reference->setChequeNumber(isset($refs->ChqNb) ? (string) $refs->ChqNb : null);
32 14
        $reference->setClearingSystemReference(isset($refs->ClrSysRef) ? (string) $refs->ClrSysRef : null);
33 14
        $reference->setAccountOwnerTransactionId(isset($refs->AcctOwnrTxId) ? (string) $refs->AcctOwnrTxId : null);
34 14
        $reference->setAccountServicerTransactionId(isset($refs->AcctSvcrTxId) ? (string) $refs->AcctSvcrTxId : null);
35 14
        $reference->setMarketInfrastructureTransactionId(isset($refs->MktInfrstrctrTxId) ? (string) $refs->MktInfrstrctrTxId : null);
36 14
        $reference->setProcessingId(isset($refs->PrcgId) ? (string) $refs->PrcgId : null);
37
38 14
        foreach ($refs->Prtry as $xmlProprietary) {
39 8
            $type = isset($xmlProprietary->Tp) ? (string) $xmlProprietary->Tp : null;
40 8
            $subReference = isset($xmlProprietary->Ref) ? (string) $xmlProprietary->Ref : null;
41
42 8
            $reference->addProprietary(new DTO\ProprietaryReference($type, $subReference));
43 14
        }
44
45 14
        $detail->addReference($reference);
46 14
    }
47
48
    /**
49
     * @param DTO\EntryTransactionDetail $detail
50
     * @param SimpleXMLElement           $xmlDetail
51
     */
52 15
    public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
53
    {
54 15
        if (false === isset($xmlDetail->RltdPties)) {
55 1
            return;
56
        }
57
58 14
        foreach ($xmlDetail->RltdPties as $xmlRelatedParty) {
59 14
            if (isset($xmlRelatedParty->Cdtr)) {
60 13
                $xmlRelatedPartyType = $xmlRelatedParty->Cdtr;
61 13
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct;
62 13
                $relatedPartyType = $creditor = new DTO\Creditor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$creditor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63 14
            } elseif (isset($xmlRelatedParty->Dbtr)) {
64 6
                $xmlRelatedPartyType = $xmlRelatedParty->Dbtr;
65 6
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct;
66 6
                $relatedPartyType = $creditor = new DTO\Debtor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$creditor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67 6
            } else {
68
                continue;
69
            }
70
71 14
            if (isset($xmlRelatedPartyType->PstlAdr)) {
72 11
                $address = new DTO\Address();
73 11
                if (isset($xmlRelatedPartyType->PstlAdr->Ctry)) {
74 11
                    $address = $address->setCountry((string) $xmlRelatedPartyType->PstlAdr->Ctry);
75 11
                }
76 11
                if (isset($xmlRelatedPartyType->PstlAdr->CtrySubDvsn)) {
77 1
                    $address = $address->setCountrySubDivision((string) $xmlRelatedPartyType->PstlAdr->CtrySubDvsn);
78 1
                }
79 1
                if (isset($xmlRelatedPartyType->PstlAdr->Dept)) {
80 1
                    $address = $address->setDepartment((string) $xmlRelatedPartyType->PstlAdr->Dept);
81
                }
82 11
                if (isset($xmlRelatedPartyType->PstlAdr->SubDept)) {
83 11
                    $address = $address->setSubDepartment((string) $xmlRelatedPartyType->PstlAdr->SubDept);
84
                }
85 14
                if (isset($xmlRelatedPartyType->PstlAdr->StrtNm)) {
86 14
                    $address = $address->setStreetName((string) $xmlRelatedPartyType->PstlAdr->StrtNm);
87 14
                }
88 14
                if (isset($xmlRelatedPartyType->PstlAdr->BldgNb)) {
89
                    $address = $address->setBuildingNumber((string) $xmlRelatedPartyType->PstlAdr->BldgNb);
90
                }
91
                if (isset($xmlRelatedPartyType->PstlAdr->PstCd)) {
92
                    $address = $address->setPostCode((string) $xmlRelatedPartyType->PstlAdr->PstCd);
93
                }
94 16
                if (isset($xmlRelatedPartyType->PstlAdr->TwnNm)) {
95
                    $address = $address->setTownName((string) $xmlRelatedPartyType->PstlAdr->TwnNm);
96 16
                }
97 1
                if (isset($xmlRelatedPartyType->PstlAdr->AdrLine)) {
98
                    foreach ($xmlRelatedPartyType->PstlAdr->AdrLine as $line) {
99
                        $address = $address->addAddressLine((string)$line);
100 15
                    }
101 6
                }
102 6
103 6
                $relatedPartyType->setAddress($address);
104 6
            }
105
106 6
            $relatedParty = new DTO\RelatedParty($relatedPartyType, $this->getRelatedPartyAccount($xmlRelatedPartyTypeAccount));
107
            $detail->addRelatedParty($relatedParty);
108
        }
109 9
    }
110 9
111 9
    /**
112 9
     * @param DTO\EntryTransactionDetail $detail
113 9
     * @param SimpleXMLElement           $xmlDetail
114 9
     */
115 9
    public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
116 9
    {
117 9
        if (false === isset($xmlDetail->RmtInf)) {
118 9
            return;
119 9
        }
120 9
121
        if (isset($xmlDetail->RmtInf->Ustrd)) {
122
            $remittanceInformation = DTO\RemittanceInformation::fromUnstructured(
123
                (string)$xmlDetail->RmtInf->Ustrd
124
            );
125
            $detail->setRemittanceInformation($remittanceInformation);
126 15
127
            return;
128 15
        }
129 1
        
130 1
        if (isset($xmlDetail->RmtInf->Strd)
131 1
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
132 1
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref)
133 1
        ) {
134 1
            $creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured(
135 15
                (string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref
136
            );
137
            $remittanceInformation = new DTO\RemittanceInformation();
138
            $remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation);
139
            $detail->setRemittanceInformation($remittanceInformation);
140
        }
141 15
    }
142
143 15
    /**
144 1
     * @param DTO\EntryTransactionDetail $detail
145 1
     * @param SimpleXMLElement           $xmlDetail
146 1
     */
147 1
    public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
148 1
    {
149 15
        if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) {
150
            $remittanceInformation = DTO\ReturnInformation::fromUnstructured(
151
                (string)$xmlDetail->RtrInf->Rsn->Cd,
152
                (string)$xmlDetail->RtrInf->AddtlInf
153
            );
154
            $detail->setReturnInformation($remittanceInformation);
155
        }
156
    }
157
158
    /**
159
     * @param DTO\EntryTransactionDetail $detail
160
     * @param SimpleXMLElement           $xmlDetail
161
     */
162
    public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
163
    {
164
        if (isset($xmlDetail->AddtlTxInf)) {
165
            $additionalInformation = new DTO\AdditionalTransactionInformation(
166
                (string) $xmlDetail->AddtlTxInf
167
            );
168
            $detail->setAdditionalTransactionInformation($additionalInformation);
169
        }
170
    }
171
172
    /**
173
     * @param SimpleXMLElement $xmlDetail
0 ignored issues
show
Bug introduced by
There is no parameter named $xmlDetail. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
174
     *
175
     * @return DTO\Account|null
176
     */
177
    abstract public function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount);
178
}
179