| Conditions | 10 |
| Paths | 11 |
| Total Lines | 72 |
| Code Lines | 41 |
| 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 |
||
| 125 | protected function transferLoans(User $localUser) |
||
| 126 | { |
||
| 127 | $almaUser = $this->alma->users[$localUser->alma_primary_id]; |
||
| 128 | |||
| 129 | if (is_null($almaUser)) { |
||
| 130 | \Log::error("Kunne ikke overføre lån fordi Alma-brukeren ikke ble funnet. Meget uventet."); |
||
| 131 | return; |
||
| 132 | } |
||
| 133 | |||
| 134 | $n = 0; |
||
| 135 | |||
| 136 | foreach ($localUser->loans as $loan) { |
||
| 137 | if ($loan->item->thing_id == 1) { |
||
| 138 | // Loan should be transferred from the temporary card to the user |
||
| 139 | |||
| 140 | $barcode = $loan->item->barcode; |
||
| 141 | $library = $loan->library; |
||
| 142 | |||
| 143 | $errBecause = "Kunne ikke overføre lån av $barcode i Alma fordi"; |
||
| 144 | |||
| 145 | if (is_null($library->temporary_barcode)) { |
||
| 146 | \Log::error("$errBecause biblioteket ikke lenger har et midlertidig lånekort."); |
||
| 147 | continue; |
||
| 148 | } |
||
| 149 | |||
| 150 | $tempUser = $this->alma->users[$library->temporary_barcode]; |
||
| 151 | |||
| 152 | if (is_null($tempUser)) { |
||
| 153 | \Log::error("$errBecause brukeren '{$library->temporary_barcode}' ikke ble funnet i Alma."); |
||
| 154 | continue; |
||
| 155 | } |
||
| 156 | |||
| 157 | $almaItem = $this->alma->items->fromBarcode($barcode); |
||
| 158 | $almaLoan = $almaItem->loan; |
||
| 159 | |||
| 160 | if (is_null($almaLoan)) { |
||
| 161 | \Log::warning("$errBecause dokumentet i mellomtiden har blitt returnert i Alma."); |
||
| 162 | continue; |
||
| 163 | } |
||
| 164 | |||
| 165 | if ($almaLoan->user_id != $library->temporary_barcode) { |
||
| 166 | \Log::warning("$errBecause dokumentet ikke lenger er utlånt til {$library->temporary_barcode}."); |
||
| 167 | continue; |
||
| 168 | } |
||
| 169 | |||
| 170 | if (count($almaItem->requests)) { |
||
| 171 | \Log::warning("$errBecause dokumentet har reserveringer."); |
||
| 172 | continue; |
||
| 173 | } |
||
| 174 | |||
| 175 | // Cross fingers |
||
| 176 | try { |
||
| 177 | $almaLoan->scanIn($library); |
||
| 178 | $almaItem->checkOut($almaUser, $library); |
||
| 179 | } catch (RequestFailed $e) { |
||
| 180 | \Log::warning($errBecause . ' ' . $e->getMessage()); |
||
| 181 | continue; |
||
| 182 | } |
||
| 183 | |||
| 184 | \Log::info(sprintf( |
||
| 185 | 'Overførte lån av <a href="%s">%s</a> til Alma-brukeren.', |
||
| 186 | action('ItemsController@show', $loan->item->id), |
||
| 187 | $barcode |
||
| 188 | )); |
||
| 189 | |||
| 190 | // Checkin local loan and delete temporary item |
||
| 191 | $loan->checkIn(); |
||
| 192 | |||
| 193 | $n++; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | $this->info(" > Overførte $n lån"); |
||
| 197 | } |
||
| 199 |
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