<?php
 namespace League\OAuth2\Client\Provider; class GoogleUser implements ResourceOwnerInterface { protected $response; public function __construct(array $response) { $this->response = $response; } public function getId() { return $this->response['sub']; } public function getName(): string { return $this->response['name']; } public function getFirstName(): ?string { return $this->getResponseValue('given_name'); } public function getLastName(): ?string { return $this->getResponseValue('family_name'); } public function getLocale(): ?string { return $this->getResponseValue('locale'); } public function getEmail(): ?string { return $this->getResponseValue('email'); } public function getEmailVerified(): ?bool { return $this->getResponseValue('email_verified'); } public function isEmailTrustworthy(): bool { $email = $this->getEmail(); if (! $email) { return false; } if ('@gmail.com' === substr($email, -10)) { return true; } if ($this->getHostedDomain() && $this->getEmailVerified()) { return true; } return false; } public function getHostedDomain(): ?string { return $this->getResponseValue('hd'); } public function getAvatar(): ?string { return $this->getResponseValue('picture'); } public function toArray(): array { return $this->response; } private function getResponseValue($key) { return $this->response[$key] ?? null; } } 