| Conditions | 12 |
| Paths | 24 |
| Total Lines | 60 |
| Code Lines | 38 |
| 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 |
||
| 158 | public function render( |
||
| 159 | $data_, |
||
| 160 | string $mode = "bibliography", |
||
| 161 | array $citationItems = [], |
||
| 162 | bool $citationAsArray = false |
||
| 163 | ) { |
||
| 164 | if (is_array($data_)) { |
||
| 165 | $data_ = CiteProcHelper::cloneArray($data_); |
||
| 166 | } |
||
| 167 | |||
| 168 | if (!in_array($mode, ['citation', 'bibliography'])) { |
||
| 169 | throw new InvalidArgumentException("\"$mode\" is not a valid mode."); |
||
| 170 | } |
||
| 171 | |||
| 172 | $this->init($citationAsArray); //initialize |
||
| 173 | |||
| 174 | |||
| 175 | if ($data_ instanceof Data\DataList) { |
||
| 176 | $dataList = $data_; |
||
| 177 | } else { |
||
| 178 | if (is_array($data_)) { |
||
| 179 | $dataList = new DataList(); |
||
| 180 | $dataList->setArray($data_); |
||
| 181 | } else { |
||
| 182 | throw new CiteProcException('No valid format for variable data. Either DataList or array expected'); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | switch ($mode) { |
||
| 187 | case 'bibliography': |
||
| 188 | self::$context->setMode($mode); |
||
| 189 | // set CitationItems to Context |
||
| 190 | self::getContext()->setCitationData($dataList); |
||
| 191 | $res = $this->bibliography($dataList); |
||
| 192 | break; |
||
| 193 | case 'citation': |
||
| 194 | if (is_array($citationItems)) { |
||
| 195 | $citeItems = emptyMap(); |
||
| 196 | $citationItems = listOfLists(...$citationItems); |
||
| 197 | foreach ($data_ as $key => $value) { |
||
| 198 | if (property_exists($value, "id") && $citationItems |
||
| 199 | ->map(fn ($item) => $item->id)->contains($value->id)) { |
||
| 200 | $k = $key + 1; |
||
| 201 | $citeItems->put("$k", $value->id); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } elseif (!($citationItems instanceof ListInterface)) { |
||
| 205 | throw new CiteProcException('No valid format for variable `citationItems`, ArrayList expected.'); |
||
| 206 | } |
||
| 207 | self::$context->setMode($mode); |
||
| 208 | // set CitationItems to Context |
||
| 209 | self::getContext()->setCitationItems($citationItems); |
||
| 210 | $res = $this->citation($dataList, $citeItems); |
||
| 211 | break; |
||
| 212 | default: |
||
| 213 | throw new CiteProcException("Invalid mode $mode"); |
||
| 214 | } |
||
| 215 | self::setContext(null); |
||
| 216 | |||
| 217 | return $res; |
||
| 218 | } |
||
| 255 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.