Conditions | 13 |
Paths | 14 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Tests | 21 |
CRAP Score | 15.6406 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
9 | 11 | public static function parse(array $xml) |
|
10 | { |
||
11 | 11 | if (isset($xml['string'])) { |
|
12 | 3 | return $xml['string']; |
|
13 | } |
||
14 | |||
15 | 9 | if (isset($xml['base64'])) { |
|
16 | 1 | return base64_decode($xml['base64'], true); |
|
17 | } |
||
18 | |||
19 | 8 | if (isset($xml['i4'])) { |
|
20 | 1 | return (int)$xml['i4']; |
|
21 | } |
||
22 | |||
23 | 7 | if (isset($xml['int'])) { |
|
24 | 3 | return (int)$xml['int']; |
|
25 | } |
||
26 | |||
27 | 6 | if (isset($xml['double'])) { |
|
28 | 1 | return (float)$xml['double']; |
|
29 | } |
||
30 | |||
31 | 5 | if (isset($xml['boolean'])) { |
|
32 | 2 | return (bool)$xml['boolean']; |
|
33 | } |
||
34 | |||
35 | 3 | if (isset($xml['dateTime.iso8601'])) { |
|
36 | 1 | return new DateTimeImmutable($xml['dateTime.iso8601']); |
|
37 | } |
||
38 | |||
39 | 2 | if (isset($xml['array'])) { |
|
40 | $array = []; |
||
41 | |||
42 | if (key($xml['array']['data']['value']) === 'struct') { |
||
43 | $xml['array']['data']['value'] = [$xml['array']['data']['value']]; |
||
44 | } |
||
45 | |||
46 | foreach ($xml['array']['data']['value'] as $item) { |
||
47 | $array[] = self::parse($item); |
||
48 | } |
||
49 | |||
50 | return $array; |
||
51 | } |
||
52 | |||
53 | 2 | if (isset($xml['struct'])) { |
|
54 | 2 | $struct = []; |
|
55 | |||
56 | 2 | foreach ($xml['struct']['member'] as $member) { |
|
57 | 2 | $struct[$member['name']] = self::parse($member['value']); |
|
58 | } |
||
59 | |||
60 | 2 | return $struct; |
|
61 | } |
||
62 | |||
63 | return $xml; |
||
64 | } |
||
65 | } |
||
66 |