| Conditions | 3 |
| Paths | 2 |
| Total Lines | 52 |
| 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 |
||
| 89 | function html2plaintext($text, $texthtml0) |
||
| 90 | { |
||
| 91 | global $smiley; |
||
| 92 | |||
| 93 | if ($texthtml0) { |
||
| 94 | $text = str_replace( |
||
| 95 | [ |
||
| 96 | '<p>', |
||
| 97 | "\n", |
||
| 98 | "\r", |
||
| 99 | ], |
||
| 100 | '', |
||
| 101 | $text |
||
| 102 | ); |
||
| 103 | $text = str_replace( |
||
| 104 | [ |
||
| 105 | '<br />', |
||
| 106 | '</p>', |
||
| 107 | ], |
||
| 108 | "\n", |
||
| 109 | $text |
||
| 110 | ); |
||
| 111 | $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); |
||
| 112 | } else { |
||
| 113 | // convert smileys ... |
||
| 114 | $countSmileyImage = count($smiley['image']); |
||
| 115 | for ($n = 0; $n < $countSmileyImage; $n++) { |
||
| 116 | $text = mb_ereg_replace( |
||
| 117 | '<img [^>]*?src=[^>]+?' . str_replace('.', '\.', $smiley['file'][$n]) . '[^>]+?>', |
||
| 118 | '[s![' . $smiley['text'][$n] . ']!s]', |
||
| 119 | $text |
||
| 120 | ); |
||
| 121 | // the [s[ ]s] is needed to protect the spaces around the smileys |
||
| 122 | } |
||
| 123 | |||
| 124 | // REDMINE-1249: Missing log text in mail notification |
||
| 125 | // simpler solution that converts html to text as the previous class html2text emptied the text completely |
||
| 126 | // implementation for line wrap, url's and probably more is missing |
||
| 127 | $text = preg_replace( "/\n\s+/", "\n", rtrim(html_entity_decode(strip_tags($text)))); |
||
| 128 | |||
| 129 | $text = str_replace( |
||
| 130 | [ |
||
| 131 | '[s![', |
||
| 132 | ']!s]', |
||
| 133 | ], |
||
| 134 | '', |
||
| 135 | $text |
||
| 136 | ); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $text; |
||
| 140 | } |
||
| 141 | |||
| 150 |