OrganisationIdentification::createFromXml()   B
last analyzed

Complexity

Conditions 8
Paths 68

Size

Total Lines 51
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8.3844

Importance

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

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 23
    public static function createFromXml(SimpleXMLElement $xmlOrganisationIdentification): DTO\OrganisationIdentification
15
    {
16
        $mapping = [
17 23
            ['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 23
        $organisationIdentification = new DTO\OrganisationIdentification();
31
32 23
        static::map($organisationIdentification, $xmlOrganisationIdentification, $mapping);
33
34 23
        if (isset($xmlOrganisationIdentification->PrtryId)) {
35 4
            $other = $xmlOrganisationIdentification->PrtryId;
36
        }
37 23
        if (isset($xmlOrganisationIdentification->Othr)) {
38 22
            $other = $xmlOrganisationIdentification->Othr;
39
        }
40
41 23
        if (isset($other)) {
42 23
            if (isset($other->Id)) {
43 23
                $organisationIdentification->setOtherId(
44 23
                    (string) $other->Id
45
                );
46
            }
47 23
            if (isset($other->Issr)) {
48 23
                $organisationIdentification->setOtherIssuer(
49 23
                    (string) $other->Issr
50
                );
51
            }
52 23
            if (isset($other->Tp)) {
53
                $organisationIdentification->setOtherType(
54
                    (string) $other->Tp
55
                );
56
            }
57 23
            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 23
        return $organisationIdentification;
65
    }
66
}
67