| Conditions | 4 |
| Paths | 3 |
| Total Lines | 12 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | public function syncUserPhoto(UserProfileSyncEvent $event) |
||
| 43 | { |
||
| 44 | if (is_a($event->getUser(), 'Jitamin\Services\Identity\LdapUserProvider')) { |
||
| 45 | $profile = $event->getProfile(); |
||
| 46 | $photo = $event->getUser()->getPhoto(); |
||
|
|
|||
| 47 | |||
| 48 | if (empty($profile['avatar_path']) && !empty($photo)) { |
||
| 49 | $this->logger->info('Saving user photo from LDAP profile'); |
||
| 50 | $this->avatarModel->uploadImageContent($profile['id'], $photo); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: