Completed
Push — master ( 091458...fe2892 )
by Oleg
03:56
created

CampaignsTest::testIntegration()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 91
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 65
nc 2
nop 0
dl 0
loc 91
rs 8.518
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
namespace OptimizelyPHPTest\Service\v2;
3
4
use PHPUnit_Framework_TestCase;
5
use WebMarketingROI\OptimizelyPHP\OptimizelyApiClient;
6
use WebMarketingROI\OptimizelyPHP\Result;
7
use WebMarketingROI\OptimizelyPHP\Service\v2\Campaigns;
8
use WebMarketingROI\OptimizelyPHP\Resource\v2\Campaign;
9
use WebMarketingROI\OptimizelyPHP\Resource\v2\CampaignResults;
10
use OptimizelyPHPTest\Service\v2\BaseServiceTest;
11
use WebMarketingROI\OptimizelyPHP\Resource\v2\Project;
12
13
class CampaignsTest extends BaseServiceTest
14
{
15
    public function testListAll()
16
    {
17
        // Mock 'OptimizelyApiClient' object to avoid real API calls
18
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
19
                            ->disableOriginalConstructor()
20
                            ->getMock();
21
22
        $result = new Result(array(
23
                        array(
24
                            "project_id" => 1000,
25
                            "changes" => array(
26
                              array(
27
                                "type" => "custom_code",
28
                                "allow_additional_redirect" => true,
29
                                "async" => true,
30
                                "css_selector" => "a[href*=\"optimizely\"]",
31
                                "dependencies" => array(
32
                                  24,
33
                                  26
34
                                ),
35
                                "destination" => "https://app.optimizely.com/",
36
                                "extension_id" => 1234,
37
                                "preserve_parameters" => true,
38
                                "src" => 524,
39
                                "value" => "window.someGlobalFunction();",
40
                                "id" => "string"
41
                              )
42
                            ),
43
                            "created" => "2016-10-18T03:27:04.123Z",
44
                            "earliest" => "2016-10-18T03:27:04.123Z",
45
                            "experiment_ids" => array(
46
                              0
47
                            ),
48
                            "holdback" => 0,
49
                            "last_modified" => "2016-10-18T03:27:04.123Z",
50
                            "latest" => "2016-10-18T03:27:04.123Z",
51
                            "metrics" => array(
52
                              array(
53
                                "kind" => "string",
54
                                "id" => 0
55
                              )
56
                            ),
57
                            "name" => "Landing Page Optimization",
58
                            "page_ids" => array(
59
                              0
60
                            ),
61
                            "status" => "active",
62
                            "type" => "a/b",
63
                            "id" => 2000
64
                          )
65
                        ), 200);
66
        
67
        $optimizelyApiClientMock->method('sendApiRequest')
68
                    ->willReturn($result);
69
        
70
        $campaignsService = new Campaigns($optimizelyApiClientMock);
71
        
72
        $result = $campaignsService->listAll(1000);
73
        $campaigns = $result->getPayload();
74
        
75
        $this->assertTrue(count($campaigns)==1);
76
        $this->assertTrue($campaigns[0] instanceOf Campaign);
77
        $this->assertTrue($campaigns[0]->getName()=='Landing Page Optimization');        
78
    }
79
    
80
    /**
81
     * @expectedException Exception
82
     */
83 View Code Duplication
    public function testListAll_InvalidPage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        // Mock 'OptimizelyApiClient' object to avoid real API calls
86
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
87
                            ->disableOriginalConstructor()
88
                            ->getMock();
89
        
90
        $campaignsService = new Campaigns($optimizelyApiClientMock);
91
        
92
        $result = $campaignsService->listAll(1000, -1, 25);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
93
    }
94
    
95
    /**
96
     * @expectedException Exception
97
     */
98 View Code Duplication
    public function testListAll_InvalidPerPage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        // Mock 'OptimizelyApiClient' object to avoid real API calls
101
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
102
                            ->disableOriginalConstructor()
103
                            ->getMock();
104
        
105
        $campaignsService = new Campaigns($optimizelyApiClientMock);
106
        
107
        $result = $campaignsService->listAll(1000, 1, 1000);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108
    }
109
    
110
    public function testGet()
111
    {
112
        // Mock 'OptimizelyApiClient' object to avoid real API calls
113
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
114
                            ->disableOriginalConstructor()
115
                            ->getMock();
116
117
        $result = new Result(array(
118
                            "project_id" => 1000,
119
                            "changes" => array(
120
                              array(
121
                                "type" => "custom_code",
122
                                "allow_additional_redirect" => true,
123
                                "async" => true,
124
                                "css_selector" => "a[href*=\"optimizely\"]",
125
                                "dependencies" => array(
126
                                  24,
127
                                  26
128
                                ),
129
                                "destination" => "https://app.optimizely.com/",
130
                                "extension_id" => 1234,
131
                                "preserve_parameters" => true,
132
                                "src" => 524,
133
                                "value" => "window.someGlobalFunction();",
134
                                "id" => "string"
135
                              )
136
                            ),
137
                            "created" => "2016-10-18T03:27:04.139Z",
138
                            "earliest" => "2016-10-18T03:27:04.139Z",
139
                            "experiment_ids" => array(
140
                              0
141
                            ),
142
                            "holdback" => 0,
143
                            "last_modified" => "2016-10-18T03:27:04.139Z",
144
                            "latest" => "2016-10-18T03:27:04.139Z",
145
                            "metrics" => array(
146
                              array(
147
                                "kind" => "string",
148
                                "id" => 0
149
                              )
150
                            ),
151
                            "name" => "Landing Page Optimization",
152
                            "page_ids" => array(
153
                              0
154
                            ),
155
                            "status" => "active",
156
                            "type" => "a/b",
157
                            "id" => 2000   
158
                        ), 200);
159
        
160
        $optimizelyApiClientMock->method('sendApiRequest')
161
                    ->willReturn($result);
162
        
163
        $campaignsService = new Campaigns($optimizelyApiClientMock);
164
        
165
        $result = $campaignsService->get(2000);
166
        $campaign = $result->getPayload();
167
        
168
        $this->assertTrue($campaign instanceOf Campaign);
169
        $this->assertTrue($campaign->getName()=='Landing Page Optimization');        
170
    }
171
    
172
    public function testGetResults()
173
    {
174
        // Mock 'OptimizelyApiClient' object to avoid real API calls
175
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
176
                            ->disableOriginalConstructor()
177
                            ->getMock();
178
179
        $result = new Result(array(
180
                            "campaign_id" => 0,
181
                            "confidence_threshold" => 0,
182
                            "end_time" => "2016-10-18T03:27:04.147Z",
183
                            "metrics" => array(
184
                              array(
185
                                "event" => "string",
186
                                "event_name" => "string",
187
                                "measure" => "conversions",
188
                                "metric_id" => "string",
189
                                "priority" => 0,
190
                                "results" => array(
191
                                  "campaign" => array(
192
                                    "experiment_id" => 0,
193
                                    "is_baseline" => true,
194
                                    "lift" => array(
195
                                      "confidence_interval" => array(
196
                                        0.010399560300730457,
197
                                        0.0850821459929161
198
                                      ),
199
                                      "is_most_conclusive" => true,
200
                                      "is_significant" => true,
201
                                      "significance" => 0,
202
                                      "value" => 0,
203
                                      "visitors_remaining" => 0
204
                                    ),
205
                                    "name" => "Blue Button",
206
                                    "rate" => 0,
207
                                    "scope" => "variation",
208
                                    "total_increase" => array(
209
                                      "confidence_interval" => array(
210
                                        0.010399560300730457,
211
                                        0.0850821459929161
212
                                      ),
213
                                      "is_most_conclusive" => true,
214
                                      "is_significant" => true,
215
                                      "significance" => 0,
216
                                      "value" => 0,
217
                                      "visitors_remaining" => 0
218
                                    ),
219
                                    "value" => 0,
220
                                    "variation_id" => "string"
221
                                  )
222
                                ),
223
                                "unit" => "session"
224
                              )
225
                            ),
226
                            "start_time" => "2016-10-18T03:27:04.148Z"
227
                        ), 200);
228
        
229
        $optimizelyApiClientMock->method('sendApiRequest')
230
                    ->willReturn($result);
231
        
232
        $campaignsService = new Campaigns($optimizelyApiClientMock);
233
        
234
        $result = $campaignsService->getResults(3000);
235
        $campaignResults = $result->getPayload();
236
        
237
        $this->assertTrue($campaignResults instanceOf CampaignResults);
238
        $this->assertTrue($campaignResults->getConfidenceThreshold()==0);        
239
        $this->assertTrue($campaignResults->getStartTime()=="2016-10-18T03:27:04.148Z");        
240
    }
241
    
242 View Code Duplication
    public function testCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
243
    {
244
        // Mock 'OptimizelyApiClient' object to avoid real API calls
245
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
246
                            ->disableOriginalConstructor()
247
                            ->getMock();
248
249
        $result = new Result(array(
250
                            "project_id" => 1000,
251
                            "changes" => array(
252
                              array(
253
                                "type" => "custom_code",
254
                                "allow_additional_redirect" => true, 
255
                                "async" => true,
256
                                "css_selector" => "a[href*=\"optimizely\"]",
257
                                "dependencies" => array(
258
                                  24,
259
                                  26
260
                                ),
261
                                "destination" => "https://app.optimizely.com/",
262
                                "extension_id" => 1234,
263
                                "preserve_parameters" => true,
264
                                "src" => 524,
265
                                "value" => "window.someGlobalFunction();",
266
                                "id" => "string"
267
                              )
268
                            ),
269
                            "created" => "2016-10-18T03:27:04.155Z",
270
                            "earliest" => "2016-10-18T03:27:04.155Z",
271
                            "experiment_ids" => array(
272
                              0
273
                            ),
274
                            "holdback" => 0,
275
                            "last_modified" => "2016-10-18T03:27:04.155Z",
276
                            "latest" => "2016-10-18T03:27:04.155Z",
277
                            "metrics" => array(
278
                              array(
279
                                "kind" => "string",
280
                                "id" => 0
281
                              )
282
                            ),
283
                            "name" => "Landing Page Optimization",
284
                            "page_ids" => array(
285
                              0
286
                            ),
287
                            "status" => "active",
288
                            "type" => "a/b",
289
                            "id" => 2000
290
                        ), 201);
291
        
292
        $optimizelyApiClientMock->method('sendApiRequest')
293
                    ->willReturn($result);
294
        
295
        $campaignsService = new Campaigns($optimizelyApiClientMock);
296
        
297
        $campaign = new Campaign(array(
298
                "project_id" => 1000,
299
                "changes" => array(
300
                  array(
301
                    "type" => "custom_code",
302
                    "allow_additional_redirect" => true,
303
                    "async" => true,
304
                    "css_selector" => "a[href*=\"optimizely\"]",
305
                    "dependencies" => array(
306
                      24,
307
                      26
308
                    ),
309
                    "destination" => "https://app.optimizely.com/",
310
                    "extension_id" => 1234,
311
                    "preserve_parameters" => true,
312
                    "src" => 524,
313
                    "value" => "window.someGlobalFunction();"
314
                  )
315
                ),
316
                "created" => "2016-10-18T03:27:04.067Z",
317
                "earliest" => "2016-10-18T03:27:04.067Z",
318
                "experiment_ids" => array(
319
                  0
320
                ),
321
                "holdback" => 0,
322
                "last_modified" => "2016-10-18T03:27:04.067Z",
323
                "latest" => "2016-10-18T03:27:04.067Z",
324
                "metrics" => array(
325
                  array(
326
                    "kind" => "string"
327
                  )
328
                ),
329
                "name" => "Landing Page Optimization",
330
                "page_ids" => array(
331
                  0
332
                ),
333
                "status" => "active",
334
                "type" => "a/b"
335
        ));
336
        
337
        $result = $campaignsService->create($campaign);
338
        $createdCampaign = $result->getPayload();
339
        
340
        $this->assertTrue($createdCampaign instanceOf Campaign);
341
        $this->assertTrue($createdCampaign->getName()=='Landing Page Optimization');                
342
    }
343
    
344 View Code Duplication
    public function testUpdate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
345
    {
346
        // Mock 'OptimizelyApiClient' object to avoid real API calls
347
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
348
                            ->disableOriginalConstructor()
349
                            ->getMock();
350
351
        $result = new Result(array(
352
                            "project_id" => 1000,
353
                            "changes" => array(
354
                              array(
355
                                "type" => "custom_code",
356
                                "allow_additional_redirect" => true, 
357
                                "async" => true,
358
                                "css_selector" => "a[href*=\"optimizely\"]",
359
                                "dependencies" => array(
360
                                  24,
361
                                  26
362
                                ),
363
                                "destination" => "https://app.optimizely.com/",
364
                                "extension_id" => 1234,
365
                                "preserve_parameters" => true,
366
                                "src" => 524,
367
                                "value" => "window.someGlobalFunction();",
368
                                "id" => "string"
369
                              )
370
                            ),
371
                            "created" => "2016-10-18T03:27:04.155Z",
372
                            "earliest" => "2016-10-18T03:27:04.155Z",
373
                            "experiment_ids" => array(
374
                              0
375
                            ),
376
                            "holdback" => 0,
377
                            "last_modified" => "2016-10-18T03:27:04.155Z",
378
                            "latest" => "2016-10-18T03:27:04.155Z",
379
                            "metrics" => array(
380
                              array(
381
                                "kind" => "string",
382
                                "id" => 0
383
                              )
384
                            ),
385
                            "name" => "Landing Page Optimization",
386
                            "page_ids" => array(
387
                              0
388
                            ),
389
                            "status" => "active",
390
                            "type" => "a/b",
391
                            "id" => 2000
392
                        ), 200);
393
        
394
        $optimizelyApiClientMock->method('sendApiRequest')
395
                    ->willReturn($result);
396
        
397
        $campaignsService = new Campaigns($optimizelyApiClientMock);
398
        
399
        $campaign = new Campaign(array(
400
                "project_id" => 1000,
401
                "changes" => array(
402
                  array(
403
                    "type" => "custom_code",
404
                    "allow_additional_redirect" => true,
405
                    "async" => true,
406
                    "css_selector" => "a[href*=\"optimizely\"]",
407
                    "dependencies" => array(
408
                      24,
409
                      26
410
                    ),
411
                    "destination" => "https://app.optimizely.com/",
412
                    "extension_id" => 1234,
413
                    "preserve_parameters" => true,
414
                    "src" => 524,
415
                    "value" => "window.someGlobalFunction();"
416
                  )
417
                ),
418
                "created" => "2016-10-18T03:27:04.067Z",
419
                "earliest" => "2016-10-18T03:27:04.067Z",
420
                "experiment_ids" => array(
421
                  0
422
                ),
423
                "holdback" => 0,
424
                "last_modified" => "2016-10-18T03:27:04.067Z",
425
                "latest" => "2016-10-18T03:27:04.067Z",
426
                "metrics" => array(
427
                  array(
428
                    "kind" => "string"
429
                  )
430
                ),
431
                "name" => "Landing Page Optimization",
432
                "page_ids" => array(
433
                  0
434
                ),
435
                "status" => "active",
436
                "type" => "a/b"
437
        ));
438
        
439
        $result = $campaignsService->update(2000, $campaign);
440
        $updatedCampaign = $result->getPayload();
441
                 
442
        $this->assertTrue($updatedCampaign instanceOf Campaign);
443
        $this->assertTrue($updatedCampaign->getName()=='Landing Page Optimization');                
444
    }
445
    
446 View Code Duplication
    public function testDelete()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
447
    {
448
        // Mock 'OptimizelyApiClient' object to avoid real API calls
449
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
450
                            ->disableOriginalConstructor()
451
                            ->getMock();
452
453
        $result = new Result(array(), 200);
454
        
455
        $optimizelyApiClientMock->method('sendApiRequest')
456
                    ->willReturn($result);
457
        
458
        $campaignsService = new Campaigns($optimizelyApiClientMock);
459
     
460
        $result = $campaignsService->delete(1000);
461
        
462
        $this->assertEquals(200, $result->getHttpCode());
463
        $this->assertEquals(null, $result->getPayload());
464
    }
465
    
466
    public function testIntegration()
467
    {
468
        if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) 
469
            $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set');
470
        
471
        $credentials = $this->loadCredentialsFromFile();
472
        
473
        $optimizelyClient = new OptimizelyApiClient($credentials, 'v2');
0 ignored issues
show
Bug introduced by
It seems like $credentials defined by $this->loadCredentialsFromFile() on line 471 can also be of type null; however, WebMarketingROI\Optimize...piClient::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
474
        $this->assertTrue($optimizelyClient!=null);
475
        
476
        // Create new project        
477
        $curDate = date('Y-m-d H:i:s');
478
        $newProject = new Project(array(
479
            "name" => "Test Project $curDate",
480
            "account_id" => 12345,
481
            "confidence_threshold" => 0.9,
482
            "platform" => "web",
483
            "status" => "active",
484
            "web_snippet" => array(
485
              "enable_force_variation" => false,
486
              "exclude_disabled_experiments" => false,
487
              "exclude_names" => true,
488
              "include_jquery" => true,
489
              "ip_anonymization" => false,
490
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
491
              "library" => "jquery-1.11.3-trim",
492
              "project_javascript" => "alert(\"Active Experiment\")"
493
            )
494
        ));
495
        
496
        $result = $optimizelyClient->projects()->create($newProject);
0 ignored issues
show
Documentation Bug introduced by
The method projects does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
497
        $createdProject = $result->getPayload();
498
        
499
        // Create new campaign in the project
500
        $campaign = new Campaign(array(
501
                "project_id" => $createdProject->getId(),
502
                "changes" => array(
503
                  array(
504
                    "type" => "custom_code",
505
                    "allow_additional_redirect" => true,
506
                    "async" => true,
507
                    "css_selector" => "a[href*=\"optimizely\"]",
508
                    "dependencies" => array(
509
                      '24',
510
                      '26'
511
                    ),
512
                    "destination" => "https://app.optimizely.com/",
513
                    "extension_id" => '1234',
514
                    "preserve_parameters" => true,
515
                    "src" => '524',
516
                    "value" => "window.someGlobalFunction();"
517
                  )
518
                ),
519
                "created" => "2016-10-18T03:27:04.067Z",
520
                "earliest" => "2016-10-18T03:27:04.067Z",
521
                "experiment_ids" => array(
522
                  0
523
                ),
524
                "holdback" => 0,
525
                "last_modified" => "2016-10-18T03:27:04.067Z",
526
                "latest" => "2016-10-18T03:27:04.067Z",
527
                "metrics" => array(
528
                  array(
529
                    "kind" => "string"
530
                  )
531
                ),
532
                "name" => "Landing Page Optimization",
533
                "page_ids" => array(
534
                  0
535
                ),
536
                "status" => "not_started",
537
                "type" => "a/b"
538
        ));
539
        
540
        $result = $optimizelyClient->campaigns()->create($campaign);
0 ignored issues
show
Documentation Bug introduced by
The method campaigns does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
541
        $createdCampaign = $result->getPayload();
542
        
543
        $this->assertTrue($createdCampaign instanceOf Campaign);
544
        $this->assertTrue($createdCampaign->getName()=='Landing Page Optimization');  
545
        
546
        // Update campaign
547
        $createdCampaign->setName('Some new compaign name');
548
        $result = $optimizelyClient->campaigns()->update($createdCampaign->getId(), $createdCampaign);
0 ignored issues
show
Documentation Bug introduced by
The method campaigns does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
549
        
550
        // Make project archived        
551
        $createdProject->setStatus('archived');
552
        $result = $optimizelyClient->projects()->update($createdProject->getId(), $createdProject);
0 ignored issues
show
Documentation Bug introduced by
The method projects does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
553
        $updatedProject = $result->getPayload();
554
        
555
        $this->assertEquals('archived', $updatedProject->getStatus());
556
    }
557
}
558
559