Conditions | 7 |
Paths | 34 |
Total Lines | 104 |
Code Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
197 | public function testIntegration() |
||
198 | { |
||
199 | if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) |
||
200 | $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set'); |
||
201 | |||
202 | $credentials = $this->loadCredentialsFromFile(); |
||
203 | |||
204 | $optimizelyClient = new OptimizelyApiClient($credentials, 'v2'); |
||
205 | $this->assertTrue($optimizelyClient!=null); |
||
206 | |||
207 | // Create new project |
||
208 | $curDate = date('Y-m-d H:i:s'); |
||
209 | $newProject = new Project(array( |
||
210 | "name" => "Test Project $curDate", |
||
211 | "account_id" => 12345, |
||
212 | "confidence_threshold" => 0.9, |
||
213 | "platform" => "web", |
||
214 | "status" => "active", |
||
215 | "web_snippet" => array( |
||
216 | "enable_force_variation" => false, |
||
217 | "exclude_disabled_experiments" => false, |
||
218 | "exclude_names" => true, |
||
219 | "include_jquery" => true, |
||
220 | "ip_anonymization" => false, |
||
221 | "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
||
222 | "library" => "jquery-1.11.3-trim", |
||
223 | "project_javascript" => "alert(\"Active Experiment\")" |
||
224 | ) |
||
225 | )); |
||
226 | |||
227 | $result = $optimizelyClient->projects()->create($newProject); |
||
228 | $createdProject = $result->getPayload(); |
||
229 | |||
230 | // Create new page in the project |
||
231 | $page = new Page(array( |
||
232 | "edit_url" => "https://www.optimizely.com", |
||
233 | "name" => "Home Page", |
||
234 | "project_id" => $createdProject->getId(), |
||
235 | "activation_type" => "immediate", |
||
236 | "archived" => false, |
||
237 | "category" => "article", |
||
238 | "conditions" => "[\"and\", {\"type\": \"url\", \"match_type\": \"substring\", \"value\": \"optimize\"}]", |
||
239 | "key" => "home_page", |
||
240 | "page_type" => "single_url", |
||
241 | "created" => "2016-10-18T05:07:04.113Z", |
||
242 | "id" => 4000, |
||
243 | "last_modified" => "2016-10-18T05:07:04.113Z" |
||
244 | )); |
||
245 | |||
246 | $result = $optimizelyClient->pages()->create($page); |
||
247 | $createdPage = $result->getPayload(); |
||
248 | |||
249 | $this->assertTrue($createdPage instanceOf Page); |
||
250 | $this->assertTrue($createdPage->getName()=='Home Page'); |
||
251 | |||
252 | // List all existing pages and try to find the created page |
||
253 | $pageFound = false; |
||
254 | try { |
||
255 | $page = 1; |
||
256 | for (;;) { |
||
257 | $result = $optimizelyClient->pages()->listAll($createdProject->getId(), $page); |
||
258 | |||
259 | $pages = $result->getPayload(); |
||
260 | |||
261 | foreach ($pages as $pageObject) { |
||
262 | if ($pageObject->getName()=="Home Page") { |
||
263 | $pageFound = true; |
||
264 | break; |
||
265 | } |
||
266 | } |
||
267 | |||
268 | if ($result->getNextPage()==null) |
||
269 | break; |
||
270 | |||
271 | $page ++; |
||
272 | } |
||
273 | } |
||
274 | catch (Exception $e) { |
||
275 | // Handle error. |
||
276 | $code = $e->getCode(); |
||
277 | $httpCode = $e->getHttpCode(); |
||
278 | $message = $e->getMessage(); |
||
279 | $uuid = $e->getUuid(); |
||
280 | echo "Exception caught: $message (code=$code http_code=$httpCode uuid=$uuid)\n"; |
||
281 | } |
||
282 | |||
283 | $this->assertTrue($pageFound); |
||
284 | |||
285 | // Update page |
||
286 | $createdPage->setName('Some new page name'); |
||
287 | $result = $optimizelyClient->pages()->update($createdPage->getId(), $createdPage); |
||
288 | $updatedPage = $result->getPayload(); |
||
289 | |||
290 | $this->assertTrue($updatedPage instanceOf Page); |
||
291 | $this->assertTrue($updatedPage->getName()=='Some new page name'); |
||
292 | |||
293 | // Make project archived |
||
294 | |||
295 | $createdProject->setStatus('archived'); |
||
296 | $result = $optimizelyClient->projects()->update($createdProject->getId(), $createdProject); |
||
297 | $updatedProject = $result->getPayload(); |
||
298 | |||
299 | $this->assertEquals('archived', $updatedProject->getStatus()); |
||
300 | } |
||
301 | } |
||
303 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: