| Conditions | 8 |
| Paths | 20 |
| Total Lines | 53 |
| Code Lines | 35 |
| 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 declare(strict_types=1); |
||
| 53 | protected function processUser(User $user) |
||
| 54 | { |
||
| 55 | if ($user->in_alma) { |
||
| 56 | // Låner er allerede koblet til Alma |
||
| 57 | if ($this->almaConnector->updateLocalUserFromAlmaUser($user)) { |
||
| 58 | if ($user->isDirty()) { |
||
| 59 | \Log::info(sprintf( |
||
| 60 | 'Brukeren <a href="%s">%s</a> ble oppdatert fra Alma.', |
||
| 61 | action('UsersController@getShow', $user->id), |
||
| 62 | $user->name |
||
| 63 | )); |
||
| 64 | } |
||
| 65 | } else { |
||
| 66 | \Log::warning(sprintf( |
||
| 67 | 'Brukeren <a href="%s">%s</a> finnes ikke lenger i Alma.', |
||
| 68 | action('UsersController@getShow', $user->id), |
||
| 69 | $user->name |
||
| 70 | )); |
||
| 71 | } |
||
| 72 | } elseif ($this->almaConnector->updateLocalUserFromAlmaUser($user)) { |
||
| 73 | // Sjekk om låner kan kobles til Alma |
||
| 74 | \Log::info(sprintf( |
||
| 75 | 'Brukeren <a href="%s">%s</a> ble koblet med en Alma-bruker.', |
||
| 76 | action('UsersController@getShow', $user->id), |
||
| 77 | $user->name |
||
| 78 | )); |
||
| 79 | $this->transferLoans($user); |
||
| 80 | } else { |
||
| 81 | // Lokal bruker |
||
| 82 | } |
||
| 83 | |||
| 84 | try { |
||
| 85 | $user->save(); |
||
| 86 | } catch (PDOException $e) { |
||
| 87 | $this->error('Konflikt!'); |
||
| 88 | \Log::warning(sprintf( |
||
| 89 | 'Brukeren <a href="%s">%s</a> kunne ikke lagres på grunn av en konflikt - to brukere har ' . |
||
| 90 | 'samme strekkode eller feide-id. Sjekk i brukerlista om det er to brukere som kan slås sammen.', |
||
| 91 | action('UsersController@getShow', $user->id), |
||
| 92 | $user->name |
||
| 93 | )); |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($user->in_alma) { |
||
| 98 | // Check if user have loans of thing_id 1 and transfer them if so. |
||
| 99 | // In case the user was manually synced during the day. |
||
| 100 | $tempLoans = $user->loans()->whereHas('item', function (Builder $query) { |
||
| 101 | $query->where('thing_id', 1); |
||
| 102 | })->count(); |
||
| 103 | |||
| 104 | if ($tempLoans) { |
||
| 105 | $this->transferLoans($user); |
||
| 106 | } |
||
| 220 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: