Total Complexity | 6 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class AlmaUserProvider implements UserProviderInterface |
||
14 | { |
||
15 | private $api; |
||
16 | private $userData; |
||
17 | private $logger; |
||
18 | |||
19 | public function __construct(AlmaApi $api, AlmaUserData $userData, LoggerInterface $logger) |
||
20 | { |
||
21 | $this->api = $api; |
||
22 | $this->userData = $userData; |
||
23 | $this->logger = $logger; |
||
24 | } |
||
25 | |||
26 | public function loadUserByUsername($username) |
||
27 | { |
||
28 | try { |
||
29 | $response = $this->api->getUserById($username); |
||
30 | return new AlmaUser($username, array('ROLE_USER'), $this->userData->getFullNameAsString($response)); |
||
31 | } catch (\GuzzleHttp\Exception\GuzzleException $e) { |
||
32 | $this->logger->error($e->getCode() . $e->getMessage()); |
||
33 | } |
||
34 | |||
35 | throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); |
||
36 | } |
||
37 | |||
38 | public function refreshUser(UserInterface $user) |
||
39 | { |
||
40 | if (!$user instanceof AlmaUser) { |
||
41 | throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); |
||
42 | } |
||
43 | return $user; |
||
44 | } |
||
45 | |||
46 | public function supportsClass($class) |
||
49 | } |
||
50 | } |
||
51 |