Failed Conditions
Pull Request — master (#92)
by
unknown
08:11
created

OrganisationIdentification::createFromXml()   B

Complexity

Conditions 8
Paths 68

Size

Total Lines 51
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8.7515

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 32
nc 68
nop 1
dl 0
loc 51
ccs 17
cts 22
cp 0.7727
crap 8.7515
rs 8.1635
c 1
b 0
f 0

How to fix   Long Method   

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
declare(strict_types=1);
4
5
namespace Genkgo\Camt\Decoder\Factory\DTO;
6
7
use Genkgo\Camt\DTO;
8
use SimpleXMLElement;
9
10
class OrganisationIdentification
11
{
12
    use Behavior\Mapping;
13
14 1
    public static function createFromXml(SimpleXMLElement $xmlOrganisationIdentification): DTO\OrganisationIdentification
15
    {
16
        $mapping = [
17 1
            ['setter' => 'setBic', 'value' => 'BIC'],
18
            ['setter' => 'setBic', 'value' => 'BICOrBEI'],
19
            ['setter' => 'setBic', 'value' => 'AnyBIC'],
20
            ['setter' => 'setBei', 'value' => 'BICOrBEI'],
21
            ['setter' => 'setIbei', 'value' => 'IBEI'],
22
            ['setter' => 'setBei', 'value' => 'BEI'],
23
            ['setter' => 'setEangln', 'value' => 'EANGLN'],
24
            ['setter' => 'setChipsUniversalId', 'value' => 'USCHU'],
25
            ['setter' => 'setDuns', 'value' => 'DUNS'],
26
            ['setter' => 'setBankPartyId', 'value' => 'BkPtyId'],
27
            ['setter' => 'setTaxId', 'value' => 'TaxIdNb'],
28
        ];
29
30 1
        $organisationIdentification = new DTO\OrganisationIdentification();
31
32 1
        static::map($organisationIdentification, $xmlOrganisationIdentification, $mapping);
33
34 1
        if (isset($xmlOrganisationIdentification->PrtryId)) {
35 1
            $other = $xmlOrganisationIdentification->PrtryId;
36
        }
37 1
        if (isset($xmlOrganisationIdentification->Othr)) {
38
            $other = $xmlOrganisationIdentification->Othr;
39
        }
40
41 1
        if (isset($other)) {
42 1
            if (isset($other->Id)) {
43 1
                $organisationIdentification->setOtherId(
44 1
                    (string) $other->Id
45
                );
46
            }
47 1
            if (isset($other->Issr)) {
48 1
                $organisationIdentification->setOtherIssuer(
49 1
                    (string) $other->Issr
50
                );
51
            }
52 1
            if (isset($other->Tp)) {
53
                $organisationIdentification->setOtherType(
54
                    (string) $other->Tp
55
                );
56
            }
57 1
            if (isset($other->SchmeNm)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $other does not seem to be defined for all execution paths leading up to this point.
Loading history...
58
                $organisationIdentification->setOtherSchemeName(
59
                    (string) $other->SchmeNm
60
                );
61
            }
62
        }
63
64 1
        return $organisationIdentification;
65
    }
66
}
67