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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

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

0.0
/src/config/semrush-client.php
1
<?php
2

3
namespace Yoast\WP\SEO\Config;
4

5
use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
6
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Property_Exception;
7
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Token_Exception;
8
use Yoast\WP\SEO\Helpers\Options_Helper;
9
use Yoast\WP\SEO\Wrappers\WP_Remote_Handler;
10
use YoastSEO_Vendor\GuzzleHttp\Client;
11
use YoastSEO_Vendor\League\OAuth2\Client\Provider\Exception\IdentityProviderException;
12
use YoastSEO_Vendor\League\OAuth2\Client\Provider\GenericProvider;
13

14
/**
15
 * Class SEMrush_Client
16
 */
17
class SEMrush_Client extends OAuth_Client {
18

19
        /**
20
         * The option's key.
21
         */
22
        const TOKEN_OPTION = 'semrush_tokens';
23

24
        /**
25
         * SEMrush_Client constructor.
26
         *
27
         * @param Options_Helper    $options_helper    The Options_Helper instance.
28
         * @param WP_Remote_Handler $wp_remote_handler The request handler.
29
         *
30
         * @throws Empty_Property_Exception Throws when one of the required properties is empty.
31
         */
32
        public function __construct(
33
                Options_Helper $options_helper,
34
                WP_Remote_Handler $wp_remote_handler
35
        ) {
36
                $provider = new GenericProvider(
×
37
                        [
×
38
                                'clientId'                => 'yoast',
×
39
                                'clientSecret'            => 'YdqNsWwnP4vE54WO1ugThKEjGMxMAHJt',
×
40
                                'redirectUri'             => 'https://oauth.semrush.com/oauth2/yoast/success',
×
41
                                'urlAuthorize'            => 'https://oauth.semrush.com/oauth2/authorize',
×
42
                                'urlAccessToken'          => 'https://oauth.semrush.com/oauth2/access_token',
×
43
                                'urlResourceOwnerDetails' => 'https://oauth.semrush.com/oauth2/resource',
×
44
                        ],
×
45
                        [
×
46
                                'httpClient' => new Client( [ 'handler' => $wp_remote_handler ] ),
×
47
                        ]
×
48
                );
×
49

50
                parent::__construct(
×
51
                        self::TOKEN_OPTION,
×
52
                        $provider,
×
53
                        $options_helper
×
54
                );
×
55
        }
56

57
        /**
58
         * Performs the specified request.
59
         *
60
         * @codeCoverageIgnore
61
         *
62
         * @param string $method  The HTTP method to use.
63
         * @param string $url     The URL to send the request to.
64
         * @param array  $options The options to pass along to the request.
65
         *
66
         * @return mixed The parsed API response.
67
         *
68
         * @throws IdentityProviderException Exception thrown if there's something wrong with the identifying data.
69
         * @throws Authentication_Failed_Exception Exception thrown if authentication has failed.
70
         * @throws Empty_Token_Exception Exception thrown if the token is empty.
71
         */
72
        public function do_request( $method, $url, array $options ) {
73
                // Add the access token to the GET parameters as well since this is what
74
                // the SEMRush API expects.
75
                $options = \array_merge_recursive(
76
                        $options,
77
                        [
78
                                'params' => [
79
                                        'access_token' => $this->get_tokens()->access_token,
80
                                ],
81
                        ]
82
                );
83

84
                return parent::do_request( $method, $url, $options );
85
        }
86
}
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