| Conditions | 5 |
| Paths | 9 |
| Total Lines | 89 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 162 | public function doAnchors($text) |
||
| 163 | { |
||
| 164 | // |
||
| 165 | // Turn Markdown link shortcuts into XHTML <a> tags. |
||
| 166 | // |
||
| 167 | if ($this->in_anchor) { |
||
| 168 | return $text; |
||
| 169 | } |
||
| 170 | $this->in_anchor = true; |
||
| 171 | |||
| 172 | // |
||
| 173 | // First, handle reference-style links: [link text] [id] |
||
| 174 | // |
||
| 175 | if ($this->features['reference_link']) { |
||
| 176 | $text = preg_replace_callback( |
||
| 177 | '{ |
||
| 178 | ( # wrap whole match in $1 |
||
| 179 | \[ |
||
| 180 | ('.$this->nested_brackets_re.') # link text = $2 |
||
| 181 | \] |
||
| 182 | |||
| 183 | [ ]? # one optional space |
||
| 184 | (?:\n[ ]*)? # one optional newline followed by spaces |
||
| 185 | |||
| 186 | \[ |
||
| 187 | (.*?) # id = $3 |
||
| 188 | \] |
||
| 189 | ) |
||
| 190 | }xs', |
||
| 191 | [&$this, '_doAnchors_reference_callback'], |
||
| 192 | $text |
||
| 193 | ); |
||
| 194 | } |
||
| 195 | |||
| 196 | // |
||
| 197 | // Next, inline-style links: [link text](url "optional title") |
||
| 198 | // |
||
| 199 | if ($this->features['inline_link']) { |
||
| 200 | $text = preg_replace_callback( |
||
| 201 | '{ |
||
| 202 | ( # wrap whole match in $1 |
||
| 203 | \[ |
||
| 204 | ('.$this->nested_brackets_re.') # link text = $2 |
||
| 205 | \] |
||
| 206 | \( # literal parent |
||
| 207 | [ \n]* |
||
| 208 | (?: |
||
| 209 | <(.+?)> # href = $3 |
||
| 210 | | |
||
| 211 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
||
| 212 | ) |
||
| 213 | [ \n]* |
||
| 214 | ( # $5 |
||
| 215 | ([\'"]) # quote char = $6 |
||
| 216 | (.*?) # Title = $7 |
||
| 217 | \6 # matching quote |
||
| 218 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
||
| 219 | )? # title is optional |
||
| 220 | \) |
||
| 221 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
||
| 222 | ) |
||
| 223 | }xs', |
||
| 224 | [&$this, '_doAnchors_inline_callback'], |
||
| 225 | $text |
||
| 226 | ); |
||
| 227 | } |
||
| 228 | |||
| 229 | // |
||
| 230 | // Last, handle reference-style shortcuts: [link text] |
||
| 231 | // These must come last in case you've also got [link text][1] |
||
| 232 | // or [link text](/foo) |
||
| 233 | // |
||
| 234 | if ($this->features['shortcut_link']) { |
||
| 235 | $text = preg_replace_callback( |
||
| 236 | '{ |
||
| 237 | ( # wrap whole match in $1 |
||
| 238 | \[ |
||
| 239 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
||
| 240 | \] |
||
| 241 | ) |
||
| 242 | }xs', |
||
| 243 | [&$this, '_doAnchors_reference_callback'], |
||
| 244 | $text |
||
| 245 | ); |
||
| 246 | } |
||
| 247 | |||
| 248 | $this->in_anchor = false; |
||
| 249 | |||
| 250 | return $text; |
||
| 251 | } |
||
| 253 |