Lines 0.00% 0 / 7
Methods 0.00% 0 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 verify 0.00% 0 / 6 0.00% 0 / 1 12
13final readonly class GoogleIdTokenVerifier implements GoogleIdTokenVerifierInterface
14{
15    public function __construct(
16        #[Autowire(env: 'OAUTH_GOOGLE_ID')] private string $oauthGoogleId,
17        // Google's signing certificates, else every API request downloads them again
18        #[Autowire(service: 'cache.app')] private CacheItemPoolInterface $cache,
19    ) {
20    }
21
22    #[\Override]
23    public function verify(string $idToken): ?array
24    {
25        try {
26            $client = new Client(['client_id' => $this->oauthGoogleId]);
27            $client->setCache($this->cache);
28            $payload = $client->verifyIdToken($idToken);
29        } catch (\UnexpectedValueException|\LogicException|\OutOfBoundsException) {
30            return null;
31        }
32
33        return \is_array($payload) ? $payload : null;
34    }
35}