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

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

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

0.0
/admin/class-remote-request.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin
6
 */
7

8
/**
9
 * This class handles a post request being send to a given endpoint.
10
 */
11
class WPSEO_Remote_Request {
12

13
        /**
14
         * Holds the post method.
15
         *
16
         * @var string
17
         */
18
        const METHOD_POST = 'post';
19

20
        /**
21
         * Holds the get method.
22
         *
23
         * @var string
24
         */
25
        const METHOD_GET = 'get';
26

27
        /**
28
         * Holds the endpoint to send the request to.
29
         *
30
         * @var string
31
         */
32
        protected $endpoint = '';
33

34
        /**
35
         * Holds the arguments to use in this request.
36
         *
37
         * @var array
38
         */
39
        protected $args = [
40
                'blocking'  => false,
41
                'timeout'   => 2,
42
        ];
43

44
        /**
45
         * Holds the response error.
46
         *
47
         * @var WP_Error|null
48
         */
49
        protected $response_error;
50

51
        /**
52
         * Holds the response body.
53
         *
54
         * @var mixed
55
         */
56
        protected $response_body;
57

58
        /**
59
         * Sets the endpoint and arguments.
60
         *
61
         * @param string $endpoint The endpoint to send the request to.
62
         * @param array  $args     The arguments to use in this request.
63
         */
64
        public function __construct( $endpoint, array $args = [] ) {
×
65
                $this->endpoint = $endpoint;
×
66
                $this->args     = wp_parse_args( $this->args, $args );
×
67
        }
68

69
        /**
70
         * Sets the request body.
71
         *
72
         * @param mixed $body The body to set.
73
         */
74
        public function set_body( $body ) {
×
75
                $this->args['body'] = $body;
×
76
        }
77

78
        /**
79
         * Sends the data to the given endpoint.
80
         *
81
         * @param string $method The type of request to send.
82
         *
83
         * @return bool True when sending data has been successful.
84
         */
85
        public function send( $method = self::METHOD_POST ) {
×
86
                switch ( $method ) {
87
                        case self::METHOD_POST:
×
88
                                $response = $this->post();
×
89
                                break;
×
90
                        case self::METHOD_GET:
×
91
                                $response = $this->get();
×
92
                                break;
×
93
                        default:
94
                                /* translators: %1$s expands to the request method  */
95
                                $response = new WP_Error( 1, sprintf( __( 'Request method %1$s is not valid.', 'wordpress-seo' ), $method ) );
×
96
                                break;
×
97
                }
98

99
                return $this->process_response( $response );
×
100
        }
101

102
        /**
103
         * Returns the value of the response error.
104
         *
105
         * @return WP_Error|null The response error.
106
         */
107
        public function get_response_error() {
×
108
                return $this->response_error;
×
109
        }
110

111
        /**
112
         * Returns the response body.
113
         *
114
         * @return mixed The response body.
115
         */
116
        public function get_response_body() {
×
117
                return $this->response_body;
×
118
        }
119

120
        /**
121
         * Processes the given response.
122
         *
123
         * @param mixed $response The response to process.
124
         *
125
         * @return bool True when response is valid.
126
         */
127
        protected function process_response( $response ) {
×
128
                if ( $response instanceof WP_Error ) {
×
129
                        $this->response_error = $response;
×
130

131
                        return false;
×
132
                }
133

134
                $this->response_body = wp_remote_retrieve_body( $response );
×
135

136
                return ( wp_remote_retrieve_response_code( $response ) === 200 );
×
137
        }
138

139
        /**
140
         * Performs a post request to the specified endpoint with set arguments.
141
         *
142
         * @return WP_Error|array The response or WP_Error on failure.
143
         */
144
        protected function post() {
×
145
                return wp_remote_post( $this->endpoint, $this->args );
×
146
        }
147

148
        /**
149
         * Performs a post request to the specified endpoint with set arguments.
150
         *
151
         * @return WP_Error|array The response or WP_Error on failure.
152
         */
153
        protected function get() {
×
154
                return wp_remote_get( $this->endpoint, $this->args );
×
155
        }
156
}
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