Conditions | 1 |
Paths | 1 |
Total Lines | 138 |
Code Lines | 98 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
89 | public function cbProvider() |
||
90 | { |
||
91 | return array( |
||
92 | array( |
||
93 | 'expectedStatusCode' => 204, |
||
94 | 'expectedResponseContent' => '', |
||
95 | 'request' => '{"notification_type": "payment"}', |
||
96 | 'testCase' => 'success', |
||
97 | 'testHeaders' => null, |
||
98 | ), |
||
99 | array( |
||
100 | 'expectedStatusCode' => 422, |
||
101 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
102 | array( |
||
103 | 'error' => array( |
||
104 | 'code' => 'INVALID_PARAMETER', |
||
105 | 'message' => 'notification_type key not found in Xsolla webhook request', |
||
106 | ), |
||
107 | ) |
||
108 | ), |
||
109 | 'request' => '{"foo": "bar"}', |
||
110 | 'testCase' => 'empty_request', |
||
111 | 'testHeaders' => null, |
||
112 | ), |
||
113 | array( |
||
114 | 'expectedStatusCode' => 422, |
||
115 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
116 | array( |
||
117 | 'error' => array( |
||
118 | 'code' => 'INVALID_PARAMETER', |
||
119 | 'message' => 'Unknown notification_type in Xsolla webhook request: unknown', |
||
120 | ), |
||
121 | ) |
||
122 | ), |
||
123 | 'request' => '{"notification_type": "unknown"}', |
||
124 | 'testCase' => 'unknown_notification_type', |
||
125 | 'testHeaders' => null, |
||
126 | ), |
||
127 | array( |
||
128 | 'expectedStatusCode' => 401, |
||
129 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
130 | array( |
||
131 | 'error' => array( |
||
132 | 'code' => 'INVALID_SIGNATURE', |
||
133 | 'message' => 'Invalid Signature. Signature provided in "Authorization" header (78143a5ac4b892a68ce8b0b8b49e26667db0fa00) does not match with expected', |
||
134 | ), |
||
135 | ) |
||
136 | ), |
||
137 | 'request' => null, |
||
138 | 'testCase' => 'invalid_signature', |
||
139 | 'testHeaders' => array('Authorization' => 'Signature 78143a5ac4b892a68ce8b0b8b49e26667db0fa00'), |
||
140 | ), |
||
141 | array( |
||
142 | 'expectedStatusCode' => 401, |
||
143 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
144 | array( |
||
145 | 'error' => array( |
||
146 | 'code' => 'INVALID_SIGNATURE', |
||
147 | 'message' => '"Authorization" header not found in Xsolla webhook request. Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting', |
||
148 | ), |
||
149 | ) |
||
150 | ), |
||
151 | 'request' => null, |
||
152 | 'testCase' => 'authorization_header_not_found', |
||
153 | 'testHeaders' => array('foo' => 'bar'), |
||
154 | ), |
||
155 | array( |
||
156 | 'expectedStatusCode' => 401, |
||
157 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
158 | array( |
||
159 | 'error' => array( |
||
160 | 'code' => 'INVALID_SIGNATURE', |
||
161 | 'message' => 'Signature not found in "Authorization" header from Xsolla webhook request: INVALID_FORMAT', |
||
162 | ), |
||
163 | ) |
||
164 | ), |
||
165 | 'request' => null, |
||
166 | 'testCase' => 'invalid_signature_format', |
||
167 | 'testHeaders' => array('Authorization' => 'INVALID_FORMAT'), |
||
168 | ), |
||
169 | array( |
||
170 | 'expectedStatusCode' => 422, |
||
171 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
172 | array( |
||
173 | 'error' => array( |
||
174 | 'code' => 'INVALID_PARAMETER', |
||
175 | 'message' => 'Unable to parse Xsolla webhook request into JSON: Syntax error.', |
||
176 | ), |
||
177 | ) |
||
178 | ), |
||
179 | 'request' => 'INVALID_REQUEST_CONTENT', |
||
180 | 'testCase' => 'invalid_request_content', |
||
181 | 'testHeaders' => null, |
||
182 | ), |
||
183 | array( |
||
184 | 'expectedStatusCode' => 401, |
||
185 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
186 | array( |
||
187 | 'error' => array( |
||
188 | 'code' => 'INVALID_CLIENT_IP', |
||
189 | 'message' => 'Client IP address (::1) not found in allowed IP addresses whitelist (159.255.220.240/28, 185.30.20.16/29, 185.30.21.0/24, 185.30.21.16/29). Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting', |
||
190 | ), |
||
191 | ) |
||
192 | ), |
||
193 | 'request' => null, |
||
194 | 'testCase' => 'invalid_ip', |
||
195 | 'testHeaders' => null, |
||
196 | ), |
||
197 | array( |
||
198 | 'expectedStatusCode' => 500, |
||
199 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
200 | array( |
||
201 | 'error' => array( |
||
202 | 'code' => 'SERVER_ERROR', |
||
203 | 'message' => 'callback_server_error', |
||
204 | ), |
||
205 | ) |
||
206 | ), |
||
207 | 'request' => '{"notification_type": "payment"}', |
||
208 | 'testCase' => 'callback_server_error', |
||
209 | 'testHeaders' => null, |
||
210 | ), |
||
211 | array( |
||
212 | 'expectedStatusCode' => 400, |
||
213 | 'expectedResponseContent' => XsollaClient::jsonEncode( |
||
214 | array( |
||
215 | 'error' => array( |
||
216 | 'code' => 'CLIENT_ERROR', |
||
217 | 'message' => 'callback_client_error', |
||
218 | ), |
||
219 | ) |
||
220 | ), |
||
221 | 'request' => '{"notification_type": "payment"}', |
||
222 | 'testCase' => 'callback_client_error', |
||
223 | 'testHeaders' => null, |
||
224 | ), |
||
225 | ); |
||
226 | } |
||
227 | } |
||
228 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state