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

Yoast / wordpress-seo / 7cd8af37a7bbbd7b964cfa8db91dfdc0d3c167de

27 Mar 2026 10:12AM UTC coverage: 52.787% (-1.1%) from 53.917%
7cd8af37a7bbbd7b964cfa8db91dfdc0d3c167de

Pull #23062

github

web-flow
Merge 77b1c5f2b into 70d176237
Pull Request #23062: Register Yoast SEO abilities about analysis scores

8535 of 16034 branches covered (53.23%)

Branch coverage included in aggregate %.

143 of 307 new or added lines in 5 files covered. (46.58%)

794 existing lines in 37 files now uncovered.

33679 of 63936 relevant lines covered (52.68%)

46793.79 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
/**
11
 * Class Code_Verifier_Repository
12
 */
13
class Code_Verifier_User_Meta_Repository implements Code_Verifier_User_Meta_Repository_Interface {
14

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

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

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

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

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

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

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

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

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

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