| Conditions | 23 |
| Paths | 105 |
| Total Lines | 52 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 32 |
| CRAP Score | 23 |
| 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 |
||
| 88 | 66 | public function render($data, $citationNumber = null) |
|
| 89 | { |
||
| 90 | 66 | $textParts = array(); |
|
| 91 | 66 | $terms = $variables = $haveVariables = $elementCount = 0; |
|
| 92 | 66 | foreach ($this->children as $child) { |
|
| 93 | 66 | $elementCount++; |
|
| 94 | |||
| 95 | 66 | if (($child instanceof Text) && |
|
| 96 | 46 | ($child->getSource() == 'term' || |
|
| 97 | 46 | $child->getSource() == 'value')) { |
|
| 98 | 26 | ++$terms; |
|
| 99 | } |
||
| 100 | |||
| 101 | 66 | if (($child instanceof Label)) { |
|
| 102 | 12 | ++$terms; |
|
| 103 | } |
||
| 104 | 66 | if (method_exists($child, "getSource") && $child->getSource() == 'variable' && |
|
| 105 | 39 | !empty($child->getVariable()) && $child->getVariable() != "date" && |
|
| 106 | 39 | !empty($data->{$child->getVariable()}) |
|
| 107 | ) { |
||
| 108 | 29 | ++$variables; |
|
| 109 | } |
||
| 110 | |||
| 111 | /** @var stdClass $data */ |
||
|
3 ignored issues
–
show
|
|||
| 112 | 66 | $text = $child->render($data, $citationNumber); |
|
| 113 | 66 | $delimiter = $this->delimiter; |
|
| 114 | 66 | if (!empty($text)) { |
|
| 115 | 65 | if ($delimiter && ($elementCount < count($this->children))) { |
|
| 116 | //check to see if the delimiter is already the last character of the text string |
||
| 117 | //if so, remove it so we don't have two of them when the group will be merged |
||
| 118 | 58 | $stext = strip_tags(trim($text)); |
|
| 119 | 58 | if ((strrpos($stext, $delimiter[0]) + 1) == strlen($stext) && strlen($stext) > 1) { |
|
| 120 | 12 | $text = str_replace($stext, '----REPLACE----', $text); |
|
| 121 | 12 | $stext = substr($stext, 0, -1); |
|
| 122 | 12 | $text = str_replace('----REPLACE----', $stext, $text); |
|
| 123 | } |
||
| 124 | } |
||
| 125 | 65 | $textParts[] = $text; |
|
| 126 | |||
| 127 | 65 | if (method_exists($child, "getSource") && $child->getSource() == 'variable' || |
|
| 128 | 64 | (method_exists($child, |
|
| 129 | 64 | "getVariable") && $child->getVariable() != "date" && !empty($child->getVariable()))) { |
|
| 130 | |||
| 131 | 54 | $haveVariables++; |
|
| 132 | } |
||
| 133 | |||
| 134 | 65 | if (method_exists($child, "getSource") && $child->getSource() == 'macro') { |
|
| 135 | 29 | $haveVariables++; |
|
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | 66 | return $this->formatting($textParts, $variables, $haveVariables, $terms); |
|
| 140 | } |
||
| 189 |