Conditions | 14 |
Paths | 6 |
Total Lines | 58 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
17 | public static function fromString($string, Translations $translations, array $options = []) |
||
18 | { |
||
19 | $xml = new SimpleXMLElement($string, null, false); |
||
20 | |||
21 | foreach ($xml->file as $file) { |
||
22 | if (isset($file->notes)) { |
||
23 | foreach ($file->notes->note as $note) { |
||
24 | $translations->setHeader($note['id'], (string) $note); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | foreach ($file->unit as $unit) { |
||
29 | foreach ($unit->segment as $segment) { |
||
30 | $targets = []; |
||
31 | |||
32 | foreach ($segment->target as $target) { |
||
33 | $targets[] = (string) $target; |
||
34 | } |
||
35 | |||
36 | |||
37 | $translation = new Translation(null, (string) $segment->source); |
||
38 | $translation->setTranslation(array_shift($targets)); |
||
39 | $translation->setPluralTranslations($targets); |
||
40 | |||
41 | if (isset($unit->notes)) { |
||
42 | foreach ($unit->notes->note as $note) { |
||
43 | switch ($note['category']) { |
||
44 | case 'context': |
||
45 | $translation = $translation->getClone((string) $note); |
||
46 | break; |
||
47 | |||
48 | case 'extracted-comment': |
||
49 | $translation->addExtractedComment((string) $note); |
||
50 | break; |
||
51 | |||
52 | case 'flag': |
||
53 | $translation->addFlag((string) $note); |
||
54 | break; |
||
55 | |||
56 | case 'reference': |
||
57 | $ref = explode(':', (string) $note, 2); |
||
58 | $translation->addReference($ref[0], isset($ref[1]) ? $ref[1] : null); |
||
59 | break; |
||
60 | |||
61 | default: |
||
62 | $translation->addComment((string) $note); |
||
63 | break; |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $translations[] = $translation; |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return $translations; |
||
74 | } |
||
75 | } |
||
76 |