| Conditions | 23 |
| Paths | 105 |
| Total Lines | 59 |
| Code Lines | 31 |
| 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 | public function render($data, $citationNumber = null) |
||
| 90 | { |
||
| 91 | $textParts = array(); |
||
| 92 | $terms = $variables = $haveVariables = $elementCount = 0; |
||
| 93 | foreach ($this->children as $child) { |
||
| 94 | $elementCount++; |
||
| 95 | |||
| 96 | if (($child instanceof Text) && |
||
| 97 | ($child->getSource() == 'term' || |
||
| 98 | $child->getSource() == 'value')) { |
||
| 99 | ++$terms; |
||
| 100 | } |
||
| 101 | |||
| 102 | if (($child instanceof Label)) { |
||
| 103 | ++$terms; |
||
| 104 | } |
||
| 105 | if (method_exists($child, "getSource") && $child->getSource() == 'variable' && |
||
| 106 | !empty($child->getVariable()) && $child->getVariable() != "date" && |
||
| 107 | !empty($data->{$child->getVariable()}) |
||
| 108 | ) { |
||
| 109 | ++$variables; |
||
| 110 | } |
||
| 111 | |||
| 112 | /* |
||
| 113 | if (method_exists($child, "getSource") && $child->getSource() == 'macro') { |
||
| 114 | //if ($this->doesRendersEmptyVariable($child, $data)) { |
||
| 115 | ++$variables; |
||
| 116 | //} |
||
| 117 | } |
||
| 118 | */ |
||
| 119 | |||
| 120 | $text = $child->render($data, $citationNumber); |
||
| 121 | $delimiter = $this->delimiter; |
||
| 122 | if (!empty($text)) { |
||
| 123 | if ($delimiter && ($elementCount < count($this->children))) { |
||
| 124 | //check to see if the delimiter is already the last character of the text string |
||
| 125 | //if so, remove it so we don't have two of them when the group will be merged |
||
| 126 | $stext = strip_tags(trim($text)); |
||
| 127 | if ((strrpos($stext, $delimiter[0]) + 1) == strlen($stext) && strlen($stext) > 1) { |
||
| 128 | $text = str_replace($stext, '----REPLACE----', $text); |
||
| 129 | $stext = substr($stext, 0, -1); |
||
| 130 | $text = str_replace('----REPLACE----', $stext, $text); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $textParts[] = $text; |
||
| 134 | |||
| 135 | if (method_exists($child, "getSource") && $child->getSource() == 'variable' || |
||
| 136 | (method_exists($child, "getVariable") && $child->getVariable() != "date" && !empty($child->getVariable()))) { |
||
| 137 | |||
| 138 | $haveVariables++; |
||
| 139 | } |
||
| 140 | |||
| 141 | if (method_exists($child, "getSource") && $child->getSource() == 'macro') { |
||
| 142 | $haveVariables++; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | return $this->formatting($textParts, $variables, $haveVariables, $terms); |
||
| 147 | } |
||
| 148 | |||
| 203 |
This check marks private properties in classes that are never used. Those properties can be removed.