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

Yoast / wordpress-seo / e57e01309ec9fc3afc714e6ce0fd243e7b6d1f90

27 May 2025 12:40PM UTC coverage: 45.733%. First build
e57e01309ec9fc3afc714e6ce0fd243e7b6d1f90

Pull #22275

github

web-flow
Merge f0a8d33c9 into 5f64dc203
Pull Request #22275: Move and refactor ai generator rest endpoints

0 of 392 new or added lines in 26 files covered. (0.0%)

15548 of 33997 relevant lines covered (45.73%)

3.64 hits per line

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

0.0
/src/ai-authorization/infrastructure/code-verifier-user-meta-repository.php
1
<?php
2

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

5
use RuntimeException;
6
use Yoast\WP\SEO\AI_Authorization\Domain\Code_Verifier;
7
use Yoast\WP\SEO\Helpers\Date_Helper;
8
use Yoast\WP\SEO\Helpers\User_Helper;
9
/**
10
 * Class Code_Verifier_Repository
11
 */
12
class Code_Verifier_User_Meta_Repository implements Code_Verifier_User_Meta_Repository_Interface {
13

14
        private const CODE_VERIFIER_VALIDITY = 300; // 5 minutes
15

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

23
        /**
24
         * The user helper.
25
         *
26
         * @var User_Helper
27
         */
28
        private $user_helper;
29

30
        /**
31
         * Code_Verifier_Repository constructor.
32
         *
33
         * @param Date_Helper $date_helper The date helper.
34
         * @param User_Helper $user_helper The user helper.
35
         */
36
        public function __construct( Date_Helper $date_helper, User_Helper $user_helper ) {
×
37
                $this->date_helper = $date_helper;
×
38
                $this->user_helper = $user_helper;
×
39
        }
40

41
        /**
42
         * Store the verification code for a user.
43
         *
44
         * @param int    $user_id    The user ID.
45
         * @param string $code       The code verifier.
46
         * @param int    $created_at The time the code was created.
47
         *
48
         * @return void
49
         */
NEW
50
        public function store_code_verifier( int $user_id, string $code, int $created_at ): void {
×
51
                $this->user_helper->update_meta(
×
52
                        $user_id,
×
53
                        'yoast_wpseo_ai_generator_code_verifier_for_blog_' . \get_current_blog_id(),
×
54
                        [
×
55
                                'code'       => $code,
×
56
                                'created_at' => $created_at,
×
57
                        ]
×
58
                );
×
59
        }
60

61
        /**
62
         * Get the verification code for a user.
63
         *
64
         * @param int $user_id The user ID.
65
         *
66
         * @throws RuntimeException If the code verifier is not found or has expired.
67
         * @return Code_Verifier The verification code or null if not found.
68
         */
69
        public function get_code_verifier( int $user_id ): ?Code_Verifier {
×
70
                $data = $this->user_helper->get_meta( $user_id, 'yoast_wpseo_ai_generator_code_verifier_for_blog_' . \get_current_blog_id(), true );
×
71

72
                if ( ! \is_array( $data ) || ! isset( $data['code'] ) || $data['code'] === '' ) {
×
73
                        throw new RuntimeException( 'Unable to retrieve the verification code.' );
×
74
                }
75

76
                if ( ! isset( $data['created_at'] ) || $data['created_at'] < ( $this->date_helper->current_time() - self::CODE_VERIFIER_VALIDITY ) ) {
×
77
                        $this->delete_code_verifier( $user_id );
×
78
                        throw new RuntimeException( 'Code verifier has expired.' );
×
79
                }
80

81
                return new Code_Verifier( $data['code'], $data['created_at'] );
×
82
        }
83

84
        /**
85
         * Delete the verification code for a user.
86
         *
87
         * @param int $user_id The user ID.
88
         *
89
         * @return void
90
         */
91
        public function delete_code_verifier( int $user_id ): void {
×
92
                $this->user_helper->delete_meta( $user_id, 'yoast_wpseo_ai_generator_code_verifier_for_blog_' . \get_current_blog_id() );
×
93
        }
94
}
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

© 2025 Coveralls, Inc