Lines 100.00% 4 / 4
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
DevGoogleIdTokenVerifier 100.00% 4 / 4 100.00% 2 / 2 4 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 verify 100.00% 3 / 3 100.00% 1 / 1 3
1<?php
2
3declare(strict_types=1);
4
5namespace App\Security;
6
7use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
8use Symfony\Component\DependencyInjection\Attribute\Autowire;
9use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
10use Symfony\Component\DependencyInjection\Attribute\When;
11
12/**
13 * dev only: accepts fake ID tokens when APP_FAKE_GOOGLE_TOKENS is enabled,
14 * so the Android debug app can be tested end to end without Google.
15 * Real Google tokens keep working.
16 */
17#[When('dev')]
18#[AsDecorator(GoogleIdTokenVerifierInterface::class)]
19final readonly class DevGoogleIdTokenVerifier implements GoogleIdTokenVerifierInterface
20{
21    public function __construct(
22        #[AutowireDecorated] private GoogleIdTokenVerifierInterface $inner,
23        #[Autowire(env: 'bool:APP_FAKE_GOOGLE_TOKENS')] private bool $fakeTokensEnabled,
24    ) {
25    }
26
27    #[\Override]
28    public function verify(string $idToken): ?array
29    {
30        if ($this->fakeTokensEnabled && \str_starts_with($idToken, 'fake|')) {
31            return new FakeGoogleIdTokenVerifier()->verify($idToken);
32        }
33
34        return $this->inner->verify($idToken);
35    }
36}