| Conditions | 3 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 25 | protected function convertHtmlToOpenXMLTag($value, $tag = "b") |
||
| 26 | { |
||
| 27 | $value_array = array(); |
||
| 28 | $run_again = false; |
||
| 29 | //this could be used instead if html was already escaped |
||
| 30 | /* |
||
| 31 | $bo = "<"; |
||
| 32 | $bc = ">"; |
||
| 33 | */ |
||
| 34 | $bo = "<"; |
||
| 35 | $bc = ">"; |
||
| 36 | |||
| 37 | //get first BOLD |
||
| 38 | $tag_open_values = explode($bo.$tag.$bc, $value, 2); |
||
| 39 | |||
| 40 | if (count($tag_open_values) > 1) |
||
| 41 | { |
||
| 42 | //save everything before the bold and close it |
||
| 43 | $value_array[] = $tag_open_values[0]; |
||
| 44 | $value_array[] = '</w:t></w:r>'; |
||
| 45 | |||
| 46 | //define styling parameters |
||
| 47 | $wrPr_open = strrpos($tag_open_values[0], '<w:rPr>'); |
||
| 48 | $wrPr_close = strrpos($tag_open_values[0], '</w:rPr>', $wrPr_open); |
||
| 49 | $neutral_style = '<w:r><w:rPr>'.substr($tag_open_values[0], ($wrPr_open + 7), ($wrPr_close - ($wrPr_open + 7))).'</w:rPr><w:t>'; |
||
| 50 | $tagged_style = '<w:r><w:rPr><w:'.$tag.'/>'.substr($tag_open_values[0], ($wrPr_open + 7), ($wrPr_close - ($wrPr_open + 7))).'</w:rPr><w:t>'; |
||
| 51 | |||
| 52 | //open new text run and make it bold, include previous styling |
||
| 53 | $value_array[] = $tagged_style; |
||
| 54 | //get everything before bold close and after |
||
| 55 | $tag_close_values = explode($bo.'/'.$tag.$bc, $tag_open_values[1], 2); |
||
| 56 | //add bold text |
||
| 57 | $value_array[] = $tag_close_values[0]; |
||
| 58 | //close bold run |
||
| 59 | $value_array[] = '</w:t></w:r>'; |
||
| 60 | //open run for after bold |
||
| 61 | $value_array[] = $neutral_style; |
||
| 62 | $value_array[] = $tag_close_values[1]; |
||
| 63 | |||
| 64 | $run_again = true; |
||
| 65 | } else { |
||
| 66 | $value_array[] = $tag_open_values[0]; |
||
| 67 | } |
||
| 68 | |||
| 69 | $value = implode('', $value_array); |
||
| 70 | |||
| 71 | if ($run_again) { |
||
| 72 | $value = $this->convertHtmlToOpenXMLTag($value, $tag); |
||
| 73 | } |
||
| 74 | |||
| 75 | return $value; |
||
| 76 | } |
||
| 77 | } |
||
| 78 |