| Conditions | 17 |
| Paths | 90 |
| Total Lines | 61 |
| Code Lines | 36 |
| 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 |
||
| 144 | public function render($data) |
||
| 145 | { |
||
| 146 | $str = ""; |
||
| 147 | $matches = []; |
||
| 148 | |||
| 149 | /* when the selection consists of “editor” and “translator”, and when the contents of these two name variables |
||
| 150 | is identical, then the contents of only one name variable is rendered. In addition, the “editortranslator” |
||
| 151 | term is used if the cs:names element contains a cs:label element, replacing the default “editor” and |
||
| 152 | “translator” terms (e.g. resulting in “Doe (editor & translator)”) */ |
||
| 153 | if ($this->variables->hasValue("editor") && $this->variables->hasValue("translator")) { |
||
| 154 | if (isset($data->editor) && isset($data->translator)) { |
||
| 155 | if (isset($name)) { |
||
|
|
|||
| 156 | $str .= $this->name->render($data->editor); |
||
| 157 | } else { |
||
| 158 | $arr = []; |
||
| 159 | foreach ($data->editor as $editor) { |
||
| 160 | $arr[] = $this->format($editor->family . ", " . $editor->given); |
||
| 161 | } |
||
| 162 | $str .= implode($this->delimiter, $arr); |
||
| 163 | } |
||
| 164 | if (isset($this->label)) { |
||
| 165 | $this->label->setVariable("editortranslator"); |
||
| 166 | $str .= $this->label->render(""); |
||
| 167 | } |
||
| 168 | $vars = $this->variables->toArray(); |
||
| 169 | $vars = array_filter($vars, function($value) { |
||
| 170 | return !($value === "editor" || $value === "translator"); |
||
| 171 | }); |
||
| 172 | $this->variables->setArray($vars); |
||
| 173 | } |
||
| 174 | } |
||
| 175 | |||
| 176 | foreach ($this->variables as $variable) { |
||
| 177 | if (isset($data->{$variable}) && (!empty($data->{$variable}))) { |
||
| 178 | $matches[] = $variable; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | |||
| 183 | |||
| 184 | $results = []; |
||
| 185 | foreach ($matches as $var) { |
||
| 186 | |||
| 187 | if (!empty($data->{$var})) { |
||
| 188 | if (!empty($this->name)) { |
||
| 189 | $name = $this->name->render($data->{$var}); |
||
| 190 | if (!empty($this->label)) { |
||
| 191 | $this->label->setVariable($var); |
||
| 192 | $name .= $this->label->render($data); |
||
| 193 | } |
||
| 194 | $results[] = $this->format($name); |
||
| 195 | } else { |
||
| 196 | foreach ($data->{$var} as $name) { |
||
| 197 | $results[] = $name->given . " " . $name->family; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | $str .= implode($this->delimiter, $results); |
||
| 203 | return $this->addAffixes($str); |
||
| 204 | } |
||
| 205 | |||
| 225 | } |
This check marks calls to
isset(...)orempty(...)that are found before the variable itself is defined. These will always have the same result.This is likely the result of code being shifted around. Consider removing these calls.