| Conditions | 12 |
| Paths | 12 |
| Total Lines | 65 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 54 | private function setElementsOrdered(array $arrayInput): void |
||
| 55 | { |
||
| 56 | $this->setElementComment($arrayInput['commentParentKey']); |
||
| 57 | $this->objXmlWriter->startElement('cac:' . $arrayInput['tag']); |
||
| 58 | $this->setExtraElement($arrayInput, 'Start'); |
||
| 59 | $arrayCustomOrder = $this->arraySettings['CustomOrder'][$arrayInput['commentParentKey']]; |
||
| 60 | foreach ($arrayCustomOrder as $value) { // get the values in expected order |
||
| 61 | if (array_key_exists($value, $arrayInput['data'])) { // because certain value are optional |
||
| 62 | $key = implode('_', [$arrayInput['commentParentKey'], $value]); |
||
| 63 | $this->setMultipleComments($arrayInput, $value); |
||
| 64 | if ($value === 'TaxSubtotal') { |
||
| 65 | foreach ($arrayInput['data'][$value] as $value2) { // multiple subt-totals |
||
| 66 | $this->setElementsOrdered([ |
||
| 67 | 'commentParentKey' => $key, |
||
| 68 | 'data' => $value2, |
||
| 69 | 'tag' => $value, |
||
| 70 | ]); |
||
| 71 | } |
||
| 72 | } elseif (in_array($value, ['Item', 'Price'])) { // single Item, single Price |
||
| 73 | $this->setElementsOrdered([ |
||
| 74 | 'commentParentKey' => $key, |
||
| 75 | 'data' => $arrayInput['data'][$value], |
||
| 76 | 'tag' => $value, |
||
| 77 | ]); |
||
| 78 | } else { |
||
| 79 | $matches = []; // scan for special values |
||
| 80 | preg_match('/^(EndpointID|.*(Amount|Quantity))$/', $value, $matches, PREG_OFFSET_CAPTURE); |
||
| 81 | if ($matches !== []) { |
||
| 82 | $this->setSingleElementWithAttribute([ |
||
| 83 | 'data' => $arrayInput['data'][$value], |
||
| 84 | 'tag' => $value, |
||
| 85 | ]); |
||
| 86 | } elseif (is_array($arrayInput['data'][$value])) { |
||
| 87 | $this->objXmlWriter->startElement('cac:' . $value); |
||
| 88 | $arrayCustomOrder2 = $this->arraySettings['CustomOrder'][$key]; |
||
| 89 | foreach ($arrayCustomOrder2 as $valueOrd2) { |
||
| 90 | if (array_key_exists($valueOrd2, $arrayInput['data'][$value])) { // 4 optional values |
||
| 91 | if (is_array($arrayInput['data'][$value][$valueOrd2])) { |
||
| 92 | $this->objXmlWriter->startElement('cac:' . $valueOrd2); |
||
| 93 | foreach ($arrayInput['data'][$value][$valueOrd2] as $key2 => $value2) { |
||
| 94 | $this->setSingleElementWithAttribute([ |
||
| 95 | 'commentParentKey' => implode('_', [$key, $valueOrd2, $valueOrd2]), |
||
| 96 | 'data' => $value2, |
||
| 97 | 'tag' => $key2, |
||
| 98 | ]); |
||
| 99 | } |
||
| 100 | $this->objXmlWriter->endElement(); |
||
| 101 | } else { |
||
| 102 | $this->setSingleElementWithAttribute([ |
||
| 103 | 'commentParentKey' => implode('_', [$key, $valueOrd2]), |
||
| 104 | 'data' => $arrayInput['data'][$value][$valueOrd2], |
||
| 105 | 'tag' => $valueOrd2, |
||
| 106 | ]); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | $this->objXmlWriter->endElement(); |
||
| 111 | } else { |
||
| 112 | $this->objXmlWriter->writeElement('cbc:' . $value, $arrayInput['data'][$value]); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | $this->setExtraElement($arrayInput, 'End'); |
||
| 118 | $this->objXmlWriter->endElement(); // $key |
||
| 119 | } |
||
| 228 |