• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 9594812bf110d67afe78816058eb15ec830063d2

15 Jul 2025 10:16AM UTC coverage: 52.595% (-1.0%) from 53.638%
9594812bf110d67afe78816058eb15ec830063d2

Pull #22432

github

web-flow
Merge branch 'trunk' into feature/ai-generator-in-free
Pull Request #22432: Merge feature branch into trunk

8341 of 15027 branches covered (55.51%)

Branch coverage included in aggregate %.

382 of 1769 new or added lines in 122 files covered. (21.59%)

2 existing lines in 2 files now uncovered.

30934 of 59648 relevant lines covered (51.86%)

40029.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ai-authorization/application/code-verifier-handler.php
1
<?php
2

3
namespace Yoast\WP\SEO\AI_Authorization\Application;
4

5
use RuntimeException;
6
use Yoast\WP\SEO\AI_Authorization\Domain\Code_Verifier;
7
use Yoast\WP\SEO\AI_Authorization\Infrastructure\Code_Verifier_User_Meta_Repository;
8
use Yoast\WP\SEO\Helpers\Date_Helper;
9
/**
10
 * Class Code_Verifier_Service
11
 * Handles the generation and validation of code verifiers for users.
12
 */
13
class Code_Verifier_Handler implements Code_Verifier_Handler_Interface {
14
        private const VALIDITY_IN_SECONDS = 300; // 5 minutes
15

16
        /**
17
         * The date helper.
18
         *
19
         * @var Date_Helper
20
         */
21
        private $date_helper;
22

23
        /**
24
         * The code verifier repository.
25
         *
26
         * @var Code_Verifier_User_Meta_Repository
27
         */
28
        private $code_verifier_repository;
29

30
        /**
31
         * Code_Verifier_Service constructor.
32
         *
33
         * @param Date_Helper                        $date_helper              The date helper.
34
         * @param Code_Verifier_User_Meta_Repository $code_verifier_repository The code verifier repository.
35
         */
NEW
36
        public function __construct( Date_Helper $date_helper, Code_Verifier_User_Meta_Repository $code_verifier_repository ) {
×
NEW
37
                $this->date_helper              = $date_helper;
×
NEW
38
                $this->code_verifier_repository = $code_verifier_repository;
×
39
        }
40

41
        /**
42
         * Generate a code verifier for a user.
43
         *
44
         * @param string $user_email The user email.
45
         *
46
         * @return Code_Verifier The generated code verifier.
47
         */
NEW
48
        public function generate( string $user_email ): Code_Verifier {
×
NEW
49
                $random_string = \substr( \str_shuffle( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ), 1, 10 );
×
NEW
50
                $code          = \hash( 'sha256', $user_email . $random_string );
×
NEW
51
                $created_at    = $this->date_helper->current_time();
×
52

NEW
53
                return new Code_Verifier( $code, $created_at );
×
54
        }
55

56
        /**
57
         * Validate the code verifier for a user.
58
         *
59
         * @param int $user_id The user ID.
60
         *
61
         * @return string The code verifier.
62
         *
63
         * @throws RuntimeException If the code verifier is expired or invalid.
64
         */
NEW
65
        public function validate( int $user_id ): string {
×
NEW
66
                $code_verifier = $this->code_verifier_repository->get_code_verifier( $user_id );
×
67

NEW
68
                if ( $code_verifier === null || $code_verifier->is_expired( self::VALIDITY_IN_SECONDS ) ) {
×
NEW
69
                        $this->code_verifier_repository->delete_code_verifier( $user_id );
×
NEW
70
                        throw new RuntimeException( 'Code verifier has expired or is invalid.' );
×
71
                }
72

NEW
73
                return $code_verifier->get_code();
×
74
        }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc