Conditions | 13 |
Paths | 4 |
Total Lines | 32 |
Code Lines | 23 |
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 |
||
59 | protected function format($text) |
||
60 | { |
||
61 | if (empty($text)) { |
||
62 | return $text; |
||
63 | } |
||
64 | |||
65 | if ($this->formattingOptions->count() > 0) { |
||
66 | $format = ""; |
||
67 | foreach ($this->formattingOptions as $option => $optionValue) { |
||
68 | if ($optionValue === "italic") { |
||
69 | $text = "<i>$text</i>"; |
||
70 | } elseif ($optionValue === "bold") { |
||
71 | $text = "<b>$text</b>"; |
||
72 | } elseif ($optionValue === "normal") { |
||
73 | $text = "$text"; |
||
74 | } elseif ($option === "vertical-align") { |
||
75 | if ($optionValue === "sub") { |
||
76 | $text = "<sub>$text</sub>"; |
||
77 | } elseif ($optionValue === "sup") { |
||
78 | $text = "<sup>$text</sup>"; |
||
79 | } |
||
80 | } elseif ($option === "text-decoration" && $optionValue === "none") { |
||
81 | $format .= ""; |
||
82 | } else { |
||
83 | $format .= "$option: $optionValue;"; |
||
84 | } |
||
85 | } |
||
86 | if (!empty($format)) { |
||
87 | $text = sprintf("<span style=\"%s\">%s</span>", $format, $text); |
||
88 | } |
||
89 | } |
||
90 | return $text; |
||
91 | } |
||
93 |