Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
| GoogleUser | |
100.00% |
11 / 11 |
|
100.00% |
11 / 11 |
11 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFirstName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getResponseValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLastName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLocale | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHostedDomain | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAvatar | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Type; |
| 6 | |
| 7 | final class GoogleUser |
| 8 | { |
| 9 | /** |
| 10 | * @param array<string> $response |
| 11 | */ |
| 12 | public function __construct( |
| 13 | private array $response |
| 14 | ) {} |
| 15 | |
| 16 | public function getId(): string |
| 17 | { |
| 18 | return $this->response['sub']; |
| 19 | } |
| 20 | |
| 21 | public function getName(): string |
| 22 | { |
| 23 | return $this->response['name']; |
| 24 | } |
| 25 | |
| 26 | public function getFirstName(): ?string |
| 27 | { |
| 28 | return $this->getResponseValue('given_name'); |
| 29 | } |
| 30 | |
| 31 | private function getResponseValue(string $key): string|null |
| 32 | { |
| 33 | return $this->response[$key] ?? null; |
| 34 | } |
| 35 | |
| 36 | public function getLastName(): ?string |
| 37 | { |
| 38 | return $this->getResponseValue('family_name'); |
| 39 | } |
| 40 | |
| 41 | public function getLocale(): ?string |
| 42 | { |
| 43 | return $this->getResponseValue('locale'); |
| 44 | } |
| 45 | |
| 46 | public function getEmail(): ?string |
| 47 | { |
| 48 | return $this->getResponseValue('email'); |
| 49 | } |
| 50 | |
| 51 | public function getHostedDomain(): ?string |
| 52 | { |
| 53 | return $this->getResponseValue('hd'); |
| 54 | } |
| 55 | |
| 56 | public function getAvatar(): ?string |
| 57 | { |
| 58 | return $this->getResponseValue('picture'); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get user data as an array. |
| 63 | * |
| 64 | * @return array<string> |
| 65 | */ |
| 66 | public function toArray(): array |
| 67 | { |
| 68 | return $this->response; |
| 69 | } |
| 70 | } |