| Conditions | 5 |
| Paths | 9 |
| Total Lines | 59 |
| 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 |
||
| 17 | public static function prettyPrint($response, $save = '') |
||
| 18 | { |
||
| 19 | if (empty($response)) { |
||
| 20 | $html = "Sem resposta"; |
||
| 21 | return $html; |
||
| 22 | } |
||
| 23 | $std = json_decode($response); |
||
| 24 | if (!empty($save)) { |
||
| 25 | file_put_contents( |
||
| 26 | "/var/www/sped/sped-efinanceira/tests/fixtures/xml/$save.xml", |
||
| 27 | $std->body |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | $doc = new \DOMDocument('1.0', 'UTF-8'); |
||
| 31 | $doc->preserveWhiteSpace = false; |
||
| 32 | $doc->formatOutput = true; |
||
| 33 | $doc->loadXML($std->body); |
||
| 34 | |||
| 35 | $html = "<pre>"; |
||
| 36 | $html .= '<h2>url</h2>'; |
||
| 37 | $html .= $std->url; |
||
| 38 | $html .= "<br>"; |
||
| 39 | $html .= '<h2>operation</h2>'; |
||
| 40 | $html .= "<br>"; |
||
| 41 | $html .= $std->operation; |
||
| 42 | $html .= "<br>"; |
||
| 43 | $html .= '<h2>action</h2>'; |
||
| 44 | $html .= $std->action; |
||
| 45 | $html .= "<br>"; |
||
| 46 | $html .= '<h2>soapver</h2>'; |
||
| 47 | $html .= $std->soapver; |
||
| 48 | $html .= "<br>"; |
||
| 49 | $html .= '<h2>parameters</h2>'; |
||
| 50 | foreach ($std->parameters as $key => $param) { |
||
| 51 | $html .= "[$key] => $param <br>"; |
||
| 52 | } |
||
| 53 | $html .= "<br>"; |
||
| 54 | $html .= '<h2>header</h2>'; |
||
| 55 | $html .= $std->header; |
||
| 56 | $html .= "<br>"; |
||
| 57 | $html .= '<h2>namespaces</h2>'; |
||
| 58 | $an = json_decode(json_encode($std->namespaces), true); |
||
| 59 | foreach ($an as $key => $nam) { |
||
| 60 | $html .= "[$key] => $nam <br>"; |
||
| 61 | } |
||
| 62 | $html .= "<br>"; |
||
| 63 | $html .= '<h2>body</h2>'; |
||
| 64 | $html .= str_replace( |
||
| 65 | ['<', '>'], |
||
| 66 | ['<','>'], |
||
| 67 | str_replace( |
||
| 68 | '<?xml version="1.0"?>', |
||
| 69 | '<?xml version="1.0" encoding="UTF-8"?>', |
||
| 70 | $doc->saveXML() |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | $html .= "</pre>"; |
||
| 74 | return $html; |
||
| 75 | } |
||
| 76 | } |
||
| 77 |