| Conditions | 17 |
| Paths | 492 |
| Total Lines | 97 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 139 | public function getMetadataFromJson($jsonData, $documentType = null) |
||
| 140 | { |
||
| 141 | $jsonObject = new JsonObject($jsonData); |
||
| 142 | |||
| 143 | if ($documentType) { |
||
| 144 | $publicationType = $documentType; |
||
| 145 | } else { |
||
| 146 | $publicationType = $jsonObject->get('$.publicationType'); |
||
| 147 | if ($publicationType && is_array($publicationType)) { |
||
| 148 | $publicationType = $publicationType[0]; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** @var \EWW\Dpf\Domain\Model\DocumentType $documentType */ |
||
| 152 | $documentType = $this->documentTypeRepository->findOneByName($publicationType); |
||
| 153 | } |
||
| 154 | |||
| 155 | $resultData = []; |
||
| 156 | |||
| 157 | if (empty($documentType)) { |
||
| 158 | // default type |
||
| 159 | $documentType = $this->documentTypeRepository->findOneByName('article'); |
||
| 160 | } |
||
| 161 | |||
| 162 | foreach ($documentType->getMetadataPage() as $metadataPage) { |
||
| 163 | |||
| 164 | foreach ($metadataPage->getMetadataGroup() as $metadataGroup) { |
||
| 165 | |||
| 166 | // Group mapping |
||
| 167 | $jsonDataObject = new JsonObject($jsonData); |
||
| 168 | $jsonGroupMapping = $metadataGroup->getJsonMapping(); |
||
| 169 | $groupItems = []; |
||
| 170 | if ($jsonGroupMapping) { |
||
| 171 | $groupItems = $jsonDataObject->get($jsonGroupMapping); |
||
| 172 | } |
||
| 173 | |||
| 174 | foreach ($groupItems as $groupItem) { |
||
| 175 | |||
| 176 | $resultGroup = [ |
||
| 177 | 'attributes' => [], |
||
| 178 | 'values' => [] |
||
| 179 | ]; |
||
| 180 | $resultGroup['mapping'] = $metadataGroup->getRelativeMapping(); |
||
| 181 | $resultGroup['modsExtensionMapping'] = $metadataGroup->getRelativeModsExtensionMapping(); |
||
| 182 | $resultGroup['modsExtensionReference'] = trim($metadataGroup->getModsExtensionReference(), " /"); |
||
| 183 | $resultGroup['groupUid'] = $metadataGroup->getUid(); |
||
| 184 | |||
| 185 | foreach ($metadataGroup->getMetadataObject() as $metadataObject) { |
||
| 186 | |||
| 187 | $json = json_encode($groupItem); |
||
| 188 | |||
| 189 | $jsonObject = new JsonObject($json); |
||
| 190 | $fieldItems = []; |
||
| 191 | $jsonFieldMapping = $metadataObject->getJsonMapping(); |
||
| 192 | |||
| 193 | if ($jsonFieldMapping) { |
||
| 194 | $fieldItems = $jsonObject->get($jsonFieldMapping); |
||
| 195 | } |
||
| 196 | |||
| 197 | foreach ($fieldItems as $fieldItem) { |
||
| 198 | $resultField = []; |
||
| 199 | |||
| 200 | if (!is_array($fieldItem)) { |
||
| 201 | $value = $fieldItem; |
||
| 202 | } else { |
||
| 203 | $value = implode("; ", $fieldItem); |
||
| 204 | } |
||
| 205 | |||
| 206 | if ($metadataObject->getDataType() == \EWW\Dpf\Domain\Model\MetadataObject::INPUT_DATA_TYPE_DATE) { |
||
| 207 | $date = date_create_from_format('d.m.Y', trim($value)); |
||
| 208 | if ($date) { |
||
| 209 | $value = date_format($date, 'Y-m-d'); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | if ($value) { |
||
| 214 | $value = str_replace('"', "'", $value); |
||
| 215 | $fieldMapping = $metadataObject->getRelativeMapping(); |
||
| 216 | $resultField['modsExtension'] = $metadataObject->getModsExtension(); |
||
| 217 | $resultField['mapping'] = $fieldMapping; |
||
| 218 | $resultField['value'] = $value; |
||
| 219 | |||
| 220 | if (strpos($fieldMapping, "@") === 0) { |
||
| 221 | $resultGroup['attributes'][] = $resultField; |
||
| 222 | } else { |
||
| 223 | $resultGroup['values'][] = $resultField; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | $resultData[] = $resultGroup;; |
||
| 230 | } |
||
| 231 | |||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | return $resultData; |
||
| 236 | } |
||
| 239 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths