| Conditions | 22 |
| Paths | 201 |
| Total Lines | 53 |
| Code Lines | 34 |
| 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 |
||
| 73 | public function render($data, $citationNumber = null) |
||
| 74 | { |
||
| 75 | $textParts = array(); |
||
| 76 | $terms = $variables = $haveVariables = $elementCount = 0; |
||
| 77 | foreach ($this->children as $child) { |
||
| 78 | $elementCount++; |
||
| 79 | if (($child instanceof Text) && |
||
| 80 | ($child->getSource() == 'term' || |
||
| 81 | $child->getSource() == 'value')) { |
||
| 82 | $terms++; |
||
| 83 | } |
||
| 84 | if (($child instanceof Label)) { |
||
| 85 | ++$terms; |
||
| 86 | } |
||
| 87 | if (method_exists($child, "getSource") && $child->getSource() == 'variable' && |
||
| 88 | !empty($child->getVariable()) && |
||
| 89 | !empty($data->{$child->getVariable()}) |
||
| 90 | ) { |
||
| 91 | ++$variables; |
||
| 92 | } |
||
| 93 | $text = $child->render($data, $citationNumber); |
||
| 94 | $delimiter = $this->delimiter; |
||
| 95 | if (!empty($text)) { |
||
| 96 | if ($delimiter && ($elementCount < count($this->children))) { |
||
| 97 | //check to see if the delimiter is already the last character of the text string |
||
| 98 | //if so, remove it so we don't have two of them when the group will be merged |
||
| 99 | $stext = strip_tags(trim($text)); |
||
| 100 | if ((strrpos($stext, $delimiter[0]) + 1) == strlen($stext) && strlen($stext) > 1) { |
||
| 101 | $text = str_replace($stext, '----REPLACE----', $text); |
||
| 102 | $stext = substr($stext, 0, -1); |
||
| 103 | $text = str_replace('----REPLACE----', $stext, $text); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | //give the text parts a name |
||
| 107 | if ($child instanceof Text) { |
||
| 108 | $textParts[$child->getVariable()] = $text; |
||
| 109 | } else { |
||
| 110 | $textParts[$elementCount] = $text; |
||
| 111 | } |
||
| 112 | |||
| 113 | if (method_exists($child, "getSource") && $child->getSource() == 'variable' || |
||
| 114 | (method_exists($child, "getVariable") && !empty($child->getVariable()))) { |
||
| 115 | |||
| 116 | $haveVariables++; |
||
| 117 | } |
||
| 118 | |||
| 119 | if (method_exists($child, "getSource") && $child->getSource() == 'macro') { |
||
| 120 | $haveVariables++; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | return $this->formatting($textParts, $variables, $haveVariables, $terms); |
||
| 125 | } |
||
| 126 | |||
| 163 |
This check marks private properties in classes that are never used. Those properties can be removed.