| Conditions | 10 |
| Paths | 76 |
| Total Lines | 66 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 37 | public function loadFile($filePath, $mandatoryFieldSettings, $contentOnly = false) |
||
| 38 | { |
||
| 39 | $results = []; |
||
| 40 | $mandatoryErrors = []; |
||
| 41 | $mandatoryFieldErrors = []; |
||
|
|
|||
| 42 | |||
| 43 | $mandatoryFields = array_map( |
||
| 44 | 'trim', |
||
| 45 | explode(',', $mandatoryFieldSettings) |
||
| 46 | ); |
||
| 47 | |||
| 48 | foreach ($mandatoryFields as $key => $value) { |
||
| 49 | $orFields = array_map( |
||
| 50 | 'trim', |
||
| 51 | explode('|', $value) |
||
| 52 | ); |
||
| 53 | $mandatoryFields[$key] = $orFields; |
||
| 54 | } |
||
| 55 | |||
| 56 | $risWosReader = new RisReader(); |
||
| 57 | |||
| 58 | if ($contentOnly) { |
||
| 59 | $risWosEntries = $risWosReader->parseFile($filePath, $contentOnly); |
||
| 60 | } else { |
||
| 61 | $risWosEntries = $risWosReader->parseFile($filePath); |
||
| 62 | } |
||
| 63 | |||
| 64 | foreach ($risWosEntries as $index => $risWosItem) { |
||
| 65 | |||
| 66 | $mandatoryFieldErrors = []; |
||
| 67 | foreach ($mandatoryFields as $combinedMandatoryField) { |
||
| 68 | |||
| 69 | $mandatoryOk = false; |
||
| 70 | foreach ($combinedMandatoryField as $key => $value) { |
||
| 71 | $mandatoryOk = $mandatoryOk || ( |
||
| 72 | array_key_exists($value, $risWosItem) |
||
| 73 | && $risWosItem[$value] |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | |||
| 77 | if (!$mandatoryOk) { |
||
| 78 | $mandatoryFieldErrors[implode('|', $combinedMandatoryField)] = implode( |
||
| 79 | '|', |
||
| 80 | $combinedMandatoryField |
||
| 81 | ); |
||
| 82 | $mandatoryErrors[$index] = [ |
||
| 83 | 'index' => $index + 1, |
||
| 84 | 'title' => $risWosItem['TI'], |
||
| 85 | 'fields' => $mandatoryFieldErrors |
||
| 86 | ]; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if (!$mandatoryErrors[$index]) { |
||
| 91 | /** @var RisWosMetadata $risWosMetadata */ |
||
| 92 | $risWosMetadata = $this->objectManager->get(RisWosMetadata::class); |
||
| 93 | $risWosMetadata->setSource(get_class($this)); |
||
| 94 | $risWosMetadata->setFeUser($this->security->getUser()->getUid()); |
||
| 95 | $risWosMetadata->setData($risWosReader->risRecordToXML($risWosItem)); |
||
| 96 | $results[] = $risWosMetadata; |
||
| 97 | } |
||
| 98 | |||
| 99 | } |
||
| 100 | $this->mandatoryErrors = $mandatoryErrors; |
||
| 101 | |||
| 102 | return $results; |
||
| 103 | } |
||
| 151 | } |