Completed
Push — master ( 8d8fd4...93bd5a )
by Nicolaas
03:00
created

getDeletedSubscribers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 6
1
<?php
2
3
/**
4
 * Main Holder page for Recipes
5
 *@author nicolaas [at] sunnysideup.co.nz
6
 */
7
class CampaignMonitorAPIConnector extends Object
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
    /**
11
     * REQUIRED!
12
     * this is the CM url for logging in.
13
     * which can be used by the client.
14
     * @var String
15
     */
16
    private static $campaign_monitor_url = "";
0 ignored issues
show
Unused Code introduced by
The property $campaign_monitor_url is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
    /**
19
     * REQUIRED!
20
     * @var String
21
     */
22
    private static $client_id = "";
0 ignored issues
show
Unused Code introduced by
The property $client_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
24
25
    /**
26
     * OPTION 1: API KEY!
27
     * @var String
28
     */
29
    private static $api_key = "";
0 ignored issues
show
Unused Code introduced by
The property $api_key is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
32
    /**
33
     * OPTION 2: OAUTH OPTION
34
     * @var String
35
     */
36
    private static $client_secret = "";
0 ignored issues
show
Unused Code introduced by
The property $client_secret is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
37
38
    /**
39
     * OPTION 2: OAUTH OPTION
40
     * @var String
41
     */
42
    private static $redirect_uri = "";
0 ignored issues
show
Unused Code introduced by
The property $redirect_uri is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
44
    /**
45
     * OPTION 2: OAUTH OPTION
46
     * @var String
47
     */
48
    private static $code = "";
0 ignored issues
show
Unused Code introduced by
The property $code is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
49
50
    /**
51
     *
52
     * @var Boolean
53
     */
54
    protected $debug = false;
55
56
    /**
57
     *
58
     * @var Boolean
59
     */
60
    protected $allowCaching = false;
61
62
    /**
63
     *
64
     * @var Int
65
     */
66
    protected $httpStatusCode = 0;
67
68
69
    /**
70
     *
71
     * must be called to use this API.
72
     */
73
    public function init()
74
    {
75
        //require_once Director::baseFolder().'/'.SS_CAMPAIGNMONITOR_DIR.'/third_party/vendor/autoload.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
        //require_once Director::baseFolder().'/'.SS_CAMPAIGNMONITOR_DIR.'/third_party/vendor/campaignmonitor/createsend-php/csrest_lists.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
    }
78
79
    /**
80
     * turn debug on or off
81
     *
82
     * @param Boolean
83
     */
84
    public function setDebug($b)
85
    {
86
        $this->debug = $b;
87
    }
88
89
    /**
90
     *
91
     * @param Boolean $b
92
     */
93
    public function setAllowCaching($b)
94
    {
95
        $this->allowCaching = $b;
96
    }
97
98
    /**
99
     *
100
     * @return Boolean
101
     */
102
    public function getAllowCaching()
103
    {
104
        return $this->allowCaching;
105
    }
106
107
    /**
108
     * provides the Authorisation Array
109
     * @return Array
110
     */
111
    protected function getAuth()
112
    {
113
        if ($auth = $this->getFromCache("getAuth")) {
114
            return $auth;
115
        } else {
116
            if ($apiKey = $this->Config()->get("api_key")) {
117
                $auth = array('api_key' => $apiKey);
118
            } else {
119
                $client_id = $this->Config()->get("client_id");
120
                $client_secret = $this->Config()->get("client_secret");
121
                $redirect_uri = $this->Config()->get("redirect_uri");
122
                $code = $this->Config()->get("code");
123
124
                $result = CS_REST_General::exchange_token($client_id, $client_secret, $redirect_uri, $code);
125
126
                if ($result->was_successful()) {
127
                    $auth = array(
128
                        'access_token' => $result->response->access_token,
129
                        'refresh_token' => $result->response->refresh_token
130
                    );
131
                    //TODO: do we need to check expiry date?
132
                    //$expires_in = $result->response->expires_in;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
133
                    # Save $access_token, $expires_in, and $refresh_token.
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
134
                    if ($this->debug) {
135
                        "access token: ".$result->response->access_token."\n";
136
                        "expires in (seconds): ".$result->response->expires_in."\n";
137
                        "refresh token: ".$result->response->refresh_token."\n";
138
                    }
139
                } else {
140
                    # If you receive '121: Expired OAuth Token', refresh the access token
141
                    if ($result->response->Code == 121) {
142
                        $wrap = new CS_REST_General($auth);
0 ignored issues
show
Unused Code introduced by
The call to CS_REST_General::__construct() has too many arguments starting with $auth.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
143
                        list($new_access_token, $new_expires_in, $new_refresh_token) = $wrap->refresh_token();
0 ignored issues
show
Unused Code introduced by
The assignment to $new_expires_in is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
144
                    }
145
                    $auth = array(
146
                        'access_token' => $new_access_token,
0 ignored issues
show
Bug introduced by
The variable $new_access_token does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
147
                        'refresh_token' => $new_refresh_token
0 ignored issues
show
Bug introduced by
The variable $new_refresh_token does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
148
                    );
149
                    if ($this->debug) {
150
                        'An error occurred:\n';
151
                        $result->response->error.': '.$result->response->error_description."\n";
152
                    }
153
                }
154
            }
155
            $this->saveToCache($auth, "getAuth");
156
            return $auth;
157
        }
158
    }
159
160
    /**
161
     * returns the result or NULL in case of an error
162
     * @param CS_REST_Wrapper_Result
163
     * @return Mixed | Null
164
     */
165
    protected function returnResult($result, $apiCall, $description)
166
    {
167
        if ($this->debug) {
168
            echo "<h1>$description ( $apiCall ) ...</h1>";
169
            if ($result->was_successful()) {
170
                echo "<h2>SUCCESS</h2>";
171
            } else {
172
                echo "<h2>FAILURE: ".$result->http_status_code."</h2>";
173
            }
174
            echo "<pre>";
175
            print_r($result);
176
            echo "</pre>";
177
            echo "<hr /><hr /><hr />";
178
            ob_flush();
179
            flush();
180
        }
181
        if ($result->was_successful()) {
182
            if (isset($result->response)) {
183
                return $result->response;
184
            }
185
            return true;
186
        } else {
187
            $this->httpStatusCode = $result->http_status_code;
188
            return null;
189
        }
190
    }
191
192
    /**
193
     * returns the HTTP code for the response.
194
     * This can be handy for debuging purposes.
195
     * @return Int
196
     */
197
    public function getHttpStatusCode()
198
    {
199
        return $this->httpStatusCode;
200
    }
201
202
    /*******************************************************
203
     * caching
204
     *
205
     *******************************************************/
206
207
    /**
208
     * @param String $name
209
     * @return Mixed
210
     */
211 View Code Duplication
    protected function getFromCache($name)
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...
212
    {
213
        if ($this->getAllowCaching()) {
214
            $name = "CampaignMonitorAPIConnector_".$name;
215
            $cache = SS_Cache::factory($name);
216
            $value = $cache->load($name);
217
            if (!$value) {
218
                return null;
219
            }
220
            return unserialize($value);
221
        }
222
    }
223
224
    /**
225
     * @param Mixed $unserializedValue
226
     * @param String $name
227
     */
228 View Code Duplication
    protected function saveToCache($unserializedValue, $name)
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...
229
    {
230
        if ($this->getAllowCaching()) {
231
            $serializedValue = serialize($unserializedValue);
232
            $name = "CampaignMonitorAPIConnector_".$name;
233
            $cache = SS_Cache::factory($name);
234
            $cache->save($serializedValue, $name);
235
            return true;
236
        }
237
    }
238
239
240
    /*******************************************************
241
     * client
242
     *
243
     *******************************************************/
244
245
    /**
246
     *
247
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
248
     * array(
249
     *     {
250
     *         'WebVersionURL' => The web version url of the campaign
251
     *         'WebVersionTextURL' => The web version url of the text version of the campaign
252
     *         'CampaignID' => The id of the campaign
253
     *         'Subject' => The campaign subject
254
     *         'Name' => The name of the campaign
255
     *         'FromName' => The from name for the campaign
256
     *         'FromEmail' => The from email address for the campaign
257
     *         'ReplyTo' => The reply to email address for the campaign
258
     *         'SentDate' => The sent data of the campaign
259
     *         'TotalRecipients' => The number of recipients of the campaign
260
     *     }
261
     */
262 View Code Duplication
    public function getCampaigns()
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...
263
    {
264
        //require_once '../../csrest_clients.php';
265
        $wrap = new CS_REST_Clients($this->Config()->get("client_id"), $this->getAuth());
266
        $result = $wrap->get_campaigns();
267
        return $this->returnResult(
268
            $result,
269
            "GET /api/v3.1/clients/{id}/campaigns",
270
            "Got sent campaigns"
271
        );
272
    }
273
274 View Code Duplication
    public function getDrafts()
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...
275
    {
276
        //require_once '../../csrest_clients.php';
277
        $wrap = new CS_REST_Clients($this->Config()->get("client_id"), $this->getAuth());
278
        $result = $wrap->get_drafts();
279
        return $this->returnResult(
280
            $result,
281
            "GET /api/v3.1/clients/{id}/drafts",
282
            "Got draft campaigns"
283
        );
284
    }
285
286
    /**
287
     * Gets all subscriber lists the current client has created
288
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
289
     * array(
290
     *     {
291
     *         'ListID' => The id of the list
292
     *         'Name' => The name of the list
293
     *     }
294
     * )
295
     */
296 View Code Duplication
    public function getLists()
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...
297
    {
298
        //require_once '../../csrest_clients.php';
299
        $wrap = new CS_REST_Clients($this->Config()->get("client_id"), $this->getAuth());
300
        $result = $wrap->get_lists();
301
        return $this->returnResult(
302
            $result,
303
            "GET /api/v3.1/clients/{id}/lists",
304
            "Got Lists"
305
        );
306
    }
307
308
    public function getScheduled()
309
    {
310
        user_error("This method is still to be implemented, see samples for an example");
311
    }
312
313
    /**
314
     * list of people that are definitely suppressed...
315
     * @param  int $page     page number
316
     * @param  int $pageSize size of page
317
     * @param  string $sortByField (email)
318
     * @param  string $sortDirection (asc)
319
     *
320
     * @return [type]                 [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
321
     */
322
    public function getSuppressionlist($page, $pageSize, $sortByField = 'email', $sortDirection = 'asc')
323
    {
324
        $wrap = new CS_REST_Clients(
325
            $this->Config()->get("client_id"),
326
            $this->getAuth()
327
        );
328
        $result = $wrap->get_suppressionlist(
329
            $page,
330
            $pageSize,
331
            $sortByField,
332
            $sortDirection
333
        );
334
        return $this->returnResult(
335
            $result,
336
            "GET /api/v3/clients/{id}/suppressionlist",
337
            "Get suppression list"
338
        );
339
340
    }
341
342 View Code Duplication
    public function getTemplates()
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...
343
    {
344
        $wrap = new CS_REST_Clients(
345
            $this->Config()->get("client_id"),
346
            $this->getAuth()
347
        );
348
        $result = $wrap->get_templates();
349
        return $this->returnResult(
350
            $result,
351
            "GET /api/v3/clients/{id}/templates",
352
            "Get Templates"
353
        );
354
    }
355
356 View Code Duplication
    public function getTemplate($templatID)
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...
357
    {
358
        $wrap = new CS_REST_Templates(
359
            $templatID,
360
            $this->getAuth()
361
        );
362
        $result = $wrap->get();
363
        return $this->returnResult(
364
            $result,
365
            "GET /api/v3/templates/{ID}",
366
            "Got Summary"
367
        );
368
    }
369
370
    /**
371
     *
372
     * @param CampaignMonitorCampaign $campaignMonitorCampaign
373
     *
374
     * @return CS_REST_Wrapper_Result
375
     */
376 View Code Duplication
    public function createTemplate($campaignMonitorCampaign)
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...
377
    {
378
        $siteConfig = SiteConfig::current_site_config();
0 ignored issues
show
Unused Code introduced by
$siteConfig 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...
379
380
        $name = "Template for ".$campaignMonitorCampaign->Name;
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<CampaignMonitorCampaign>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
381
        if (!$name) {
382
            $name = "no name set";
383
        }
384
385
        $wrap = new CS_REST_Templates(null, $this->getAuth());
386
        $result = $wrap->create(
387
            $this->Config()->get("client_id"),
388
            array(
389
                'Name' => $name,
390
                'HtmlPageURL' => $campaignMonitorCampaign->PreviewLink(),
391
                'ZipFileURL' => ''
392
            )
393
        );
394
        if (isset($result->http_status_code) && ($result->http_status_code == 201 || $result->http_status_code == 201)) {
395
            $code = $result->response;
396
            $campaignMonitorCampaign->CreateFromWebsite = false;
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
397
            $campaignMonitorCampaign->CreatedFromWebsite = true;
0 ignored issues
show
Bug introduced by
The property CreatedFromWebsite does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
398
            $campaignMonitorCampaign->TemplateID = $code;
0 ignored issues
show
Documentation introduced by
The property TemplateID does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
399
        } else {
400
            $campaignMonitorCampaign->CreateFromWebsite = false;
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
401
            $campaignMonitorCampaign->CreatedFromWebsite = false;
0 ignored issues
show
Bug introduced by
The property CreatedFromWebsite does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
402
            $code = "Error";
403
            if (is_object($result->response)) {
404
                $code = $result->response->Code.":".$result->response->Message;
405
            }
406
            $campaignMonitorCampaign->MessageFromNewsletterServer = $code;
0 ignored issues
show
Documentation introduced by
The property MessageFromNewsletterServer does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
407
        }
408
        $campaignMonitorCampaign->write();
409
        return $this->returnResult(
410
            $result,
411
            "POST /api/v3/templates/{clientID}",
412
            "Created Template"
413
        );
414
    }
415
416
    /**
417
     *
418
     * @param CampaignMonitorCampaign $campaignMonitorCampaign
419
     * @param string $templateID
420
     *
421
     * @return CS_REST_Wrapper_Result
422
     */
423 View Code Duplication
    public function updateTemplate($campaignMonitorCampaign, $templateID)
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...
424
    {
425
        $siteConfig = SiteConfig::current_site_config();
0 ignored issues
show
Unused Code introduced by
$siteConfig 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...
426
427
        $name = "Template for ".$campaignMonitorCampaign->Name;
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<CampaignMonitorCampaign>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
428
        if (!$name) {
429
            $name = "no name set";
430
        }
431
        $wrap = new CS_REST_Templates($templateID, $this->getAuth());
432
        $result = $wrap->create(
433
            $this->Config()->get("client_id"),
434
            array(
435
                'Name' => $name,
436
                'HtmlPageURL' => $campaignMonitorCampaign->PreviewLink(),
437
                'ZipFileURL' => ''
438
            )
439
        );
440
        if (isset($result->http_status_code) && ($result->http_status_code == 201 || $result->http_status_code == 201)) {
441
            $code = $result->response;
0 ignored issues
show
Unused Code introduced by
$code 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...
442
            $campaignMonitorCampaign->CreateFromWebsite = false;
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
443
            $campaignMonitorCampaign->CreatedFromWebsite = true;
0 ignored issues
show
Bug introduced by
The property CreatedFromWebsite does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
444
        } else {
445
            $campaignMonitorCampaign->CreateFromWebsite = false;
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
446
            $campaignMonitorCampaign->CreatedFromWebsite = false;
0 ignored issues
show
Bug introduced by
The property CreatedFromWebsite does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
447
            $code = "Error";
448
            if (is_object($result->response)) {
449
                $code = $result->response->Code.":".$result->response->Message;
450
            }
451
            $campaignMonitorCampaign->MessageFromNewsletterServer = $code;
0 ignored issues
show
Documentation introduced by
The property MessageFromNewsletterServer does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
452
        }
453
        $campaignMonitorCampaign->write();
454
        return $this->returnResult(
455
            $result,
456
            "PUT /api/v3/templates/{ID}",
457
            "Updated Template"
458
        );
459
    }
460
461 View Code Duplication
    public function deleteTemplate($templateID)
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...
462
    {
463
        $wrap = new CS_REST_Templates($templateID, $this->getAuth());
464
        $result = $wrap->delete();
465
        return $this->returnResult(
466
            $result,
467
            "DELETE /api/v3/templates/{ID}",
468
            "Deleted Template"
469
        );
470
    }
471
472
    /*******************************************************
473
     * lists
474
     *
475
     *******************************************************/
476
477
    /**
478
     * Creates a new list based on the provided details.
479
     * Both the UnsubscribePage and the ConfirmationSuccessPage parameters are optional
480
     *
481
     * @param string $title - the page to redirect subscribers to when they unsubscribeThe list title
482
     * @param string $unsubscribePage - The page to redirect subscribers to when they unsubscribe
483
     * @param boolean $confirmedOptIn - Whether this list requires confirmation of subscription
484
     * @param string $confirmationSuccessPage - The page to redirect subscribers to when they confirm their subscription
485
     * @param string $unsubscribeSetting - Unsubscribe setting must be CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS or CS_REST_LIST_UNSUBSCRIBE_SETTING_ONLY_THIS_LIST.  See the documentation for details: http://www.campaignmonitor.com/api/lists/#creating_a_list
0 ignored issues
show
Documentation introduced by
Should the type for parameter $unsubscribeSetting not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
486
     *
487
     * @return CS_REST_Wrapper_Result A successful response will be the ID of the newly created list
488
     */
489
    public function createList($title, $unsubscribePage, $confirmedOptIn = false, $confirmationSuccessPage, $unsubscribeSetting = null)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
490
    {
491
        //require_once '../../csrest_lists.php';
492
        $wrap = new CS_REST_Lists(null, $this->getAuth());
493
        //we need to do this afterwards otherwise the definition below
494
        //is not recognised
495
        if (!$unsubscribeSetting) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $unsubscribeSetting of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
496
            $unsubscribeSetting = CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS;
497
        }
498
        $result = $wrap->create(
499
            $this->Config()->get("client_id"),
500
            array(
501
                'Title' => $title,
502
                'UnsubscribePage' => $unsubscribePage,
503
                'ConfirmedOptIn' => $confirmedOptIn,
504
                'ConfirmationSuccessPage' => $confirmationSuccessPage,
505
                'UnsubscribeSetting' => $unsubscribeSetting
506
            )
507
        );
508
        return $this->returnResult(
509
            $result,
510
            "POST /api/v3.1/lists/{clientID}",
511
            "Created with ID"
512
        );
513
    }
514
515
    /**
516
     * Creates custom field for list
517
     *
518
     * @param string $listID - list ID
519
     * @param string $type - type of custom field
520
     * @param string $title - field type
521
     * @param array $options - options for dropdown field type
522
     *
523
     * @return CS_REST_Wrapper_Result A successful response will be the key of the newly created custom field
524
     */
525
    public function createCustomField($listID, $visible, $type, $title, $options = array())
526
    {
527
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
528
        switch ($type) {
529
            case "text":
530
                $type = CS_REST_CUSTOM_FIELD_TYPE_TEXT;
531
                break;
532
            case "number":
533
                $type = CS_REST_CUSTOM_FIELD_TYPE_NUMBER;
534
                break;
535
            case "multi_select_one":
536
                $type = CS_REST_CUSTOM_FIELD_TYPE_MULTI_SELECTONE;
537
                break;
538
            case "multi_select_many":
539
                $type = CS_REST_CUSTOM_FIELD_TYPE_MULTI_SELECTMANY;
540
                break;
541
            case "date":
542
                $type = CS_REST_CUSTOM_FIELD_TYPE_DATE;
543
                break;
544
            default:
545
                user_error("You must select one from text, number, multi_select_one, multi_select_many, date)");
546
        }
547
        $result = $wrap->create_custom_field(array(
548
            'FieldName' => $title,
549
            'DataType' => $type,
550
            'Options' => $options,
551
            'VisibleInPreferenceCenter' => $visible ? true : false
552
        ));
553
        return $this->returnResult(
554
            $result,
555
            "POST /api/v3/lists/{ID}/customfields",
556
            "Created Custom Field for $listID "
557
        );
558
    }
559
560
    /**
561
     * Creates custom field for list
562
     *
563
     * @param string $listID - list ID
564
     * @param string $key
565
     *
566
     * @return CS_REST_Wrapper_Result
567
     */
568 View Code Duplication
    public function deleteCustomField($listID, $key)
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...
569
    {
570
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
571
        $result = $wrap->delete_custom_field($key);
572
        return $this->returnResult(
573
            $result,
574
            "DELETE /api/v3/lists/{ID}/{Key}",
575
            "Delete Custom Field for $listID with key $key"
576
        );
577
    }
578
579
    /**
580
     * Deletes an existing list from the system
581
     * @param Int $listID
582
     * @return CS_REST_Wrapper_Result A successful response will be empty
583
     */
584 View Code Duplication
    public function deleteList($listID)
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...
585
    {
586
        //require_once '../../csrest_lists.php';
587
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
588
        $result = $wrap->delete();
589
        return $this->returnResult(
590
            $result,
591
            "DELETE /api/v3.1/lists/{ID}",
592
            "Deleted with code"
593
        );
594
    }
595
596
    /**
597
     * Gets the basic details of the current list
598
     *
599
     * @param Int $listID
600
     *
601
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
602
     * {
603
     *     'ListID' => The id of the list
604
     *     'Title' => The title of the list
605
     *     'UnsubscribePage' => The page which subscribers are redirected to upon unsubscribing
606
     *     'ConfirmedOptIn' => Whether the list is Double-Opt In
607
     *     'ConfirmationSuccessPage' => The page which subscribers are
608
     *         redirected to upon confirming their subscription
609
     *     'UnsubscribeSetting' => The unsubscribe setting for the list. Will
610
     *         be either CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS or
611
     *         CS_REST_LIST_UNSUBSCRIBE_SETTING_ONLY_THIS_LIST.
612
     * }
613
     */
614 View Code Duplication
    public function getList($listID)
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...
615
    {
616
        //require_once '../../csrest_lists.php';
617
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
618
        $result = $wrap->get();
619
        return $this->returnResult(
620
            $result,
621
            "GET /api/v3.1/lists/{ID}",
622
            "Got list details"
623
        );
624
    }
625
626
    /**
627
     * Gets all active subscribers added since the given date
628
     *
629
     * @param Int $listID
630
     * @param string $daysAgo The date to start getting subscribers from
0 ignored issues
show
Documentation introduced by
Should the type for parameter $daysAgo not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
631
     * @param int $page The page number to get
632
     * @param int $pageSize The number of records per page
633
     * @param string $sortByField ('EMAIL', 'NAME', 'DATE')
634
     * @param string $sortDirection ('ASC', 'DESC')
635
     *
636
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
637
     * {
638
     *     'ResultsOrderedBy' => The field the results are ordered by
639
     *     'OrderDirection' => The order direction
640
     *     'PageNumber' => The page number for the result set
641
     *     'PageSize' => The page size used
642
     *     'RecordsOnThisPage' => The number of records returned
643
     *     'TotalNumberOfRecords' => The total number of records available
644
     *     'NumberOfPages' => The total number of pages for this collection
645
     *     'Results' => array(
646
     *         {
647
     *             'EmailAddress' => The email address of the subscriber
648
     *             'Name' => The name of the subscriber
649
     *             'Date' => The date that the subscriber was added to the list
650
     *             'State' => The current state of the subscriber, will be 'Active'
651
     *             'CustomFields' => array (
652
     *                 {
653
     *                     'Key' => The personalisation tag of the custom field
654
     *                     'Value' => The value of the custom field for this subscriber
655
     *                 }
656
     *             )
657
     *         }
658
     *     )
659
     * }
660
     */
661 View Code Duplication
    public function getActiveSubscribers($listID, $daysAgo = 3650, $page = 1, $pageSize = 999, $sortByField = "DATE", $sortDirection = "DESC")
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...
662
    {
663
        //require_once '../../csrest_lists.php';
664
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
665
        $result = $wrap->get_active_subscribers(
666
            date('Y-m-d', strtotime('-'.$daysAgo.' days')),
667
            $page,
668
            $pageSize,
669
            $sortByField,
670
            $sortDirection
671
        );
672
        return $this->returnResult(
673
            $result,
674
            "GET /api/v3.1/lists/{ID}/active",
675
            "Got active subscribers"
676
        );
677
    }
678
679
    /**
680
     * Gets all unconfirmed subscribers added since the given date
681
     *
682
     * @param Int $listID
683
     * @param string $daysAgo The date to start getting subscribers from
0 ignored issues
show
Documentation introduced by
Should the type for parameter $daysAgo not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
684
     * @param int $page The page number to get
685
     * @param int $pageSize The number of records per page
686
     * @param string $sortByField ('EMAIL', 'NAME', 'DATE')
687
     * @param string $sortDirection ('ASC', 'DESC')
688
     *
689
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
690
     * {
691
     *     'ResultsOrderedBy' => The field the results are ordered by
692
     *     'OrderDirection' => The order direction
693
     *     'PageNumber' => The page number for the result set
694
     *     'PageSize' => The page size used
695
     *     'RecordsOnThisPage' => The number of records returned
696
     *     'TotalNumberOfRecords' => The total number of records available
697
     *     'NumberOfPages' => The total number of pages for this collection
698
     *     'Results' => array(
699
     *         {
700
     *             'EmailAddress' => The email address of the subscriber
701
     *             'Name' => The name of the subscriber
702
     *             'Date' => The date that the subscriber was added to the list
703
     *             'State' => The current state of the subscriber, will be 'Unconfirmed'
704
     *             'CustomFields' => array (
705
     *                 {
706
     *                     'Key' => The personalisation tag of the custom field
707
     *                     'Value' => The value of the custom field for this subscriber
708
     *                 }
709
     *             )
710
     *         }
711
     *     )
712
     * }
713
     */
714 View Code Duplication
    public function getUnconfirmedSubscribers($listID, $daysAgo = 3650, $page = 1, $pageSize = 999, $sortByField = "DATE", $sortDirection = "DESC")
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...
715
    {
716
        //require_once '../../csrest_lists.php';
717
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
718
        $result = $wrap->get_unconfirmed_subscribers(
719
            date('Y-m-d', strtotime('-'.$daysAgo.' days')),
720
            $page,
721
            $pageSize,
722
            $sortByField,
723
            $sortDirection
724
        );
725
        return $this->returnResult(
726
            $result,
727
            "GET /api/v3.1/lists/{ID}/unconfirmed",
728
            "Got unconfimred subscribers"
729
        );
730
    }
731
732
    /**
733
     * Gets all bounced subscribers who have bounced out since the given date
734
     *
735
     * @param Int $listID
736
     * @param string $daysAgo The date to start getting subscribers from
0 ignored issues
show
Documentation introduced by
Should the type for parameter $daysAgo not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
737
     * @param int $page The page number to get
738
     * @param int $pageSize The number of records per page
739
     * @param string $sortByField ('EMAIL', 'NAME', 'DATE')
740
     * @param string $sortDirection ('ASC', 'DESC')
741
     *
742
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
743
     * {
744
     *     'ResultsOrderedBy' => The field the results are ordered by
745
     *     'OrderDirection' => The order direction
746
     *     'PageNumber' => The page number for the result set
747
     *     'PageSize' => The page size used
748
     *     'RecordsOnThisPage' => The number of records returned
749
     *     'TotalNumberOfRecords' => The total number of records available
750
     *     'NumberOfPages' => The total number of pages for this collection
751
     *     'Results' => array(
752
     *         {
753
     *             'EmailAddress' => The email address of the subscriber
754
     *             'Name' => The name of the subscriber
755
     *             'Date' => The date that the subscriber bounced out of the list
756
     *             'State' => The current state of the subscriber, will be 'Bounced'
757
     *             'CustomFields' => array (
758
     *                 {
759
     *                     'Key' => The personalisation tag of the custom field
760
     *                     'Value' => The value of the custom field for this subscriber
761
     *                 }
762
     *             )
763
     *         }
764
     *     )
765
     * }
766
     */
767 View Code Duplication
    public function getBouncedSubscribers($listID, $daysAgo = 3650, $page = 1, $pageSize = 999, $sortByField = "DATE", $sortDirection = "DESC")
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...
768
    {
769
        //require_once '../../csrest_lists.php';
770
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
771
        $result = $wrap->get_bounced_subscribers(
772
            date('Y-m-d', strtotime('-'.$daysAgo.' days')),
773
            $page,
774
            $pageSize,
775
            $sortByField,
776
            $sortDirection
777
        );
778
        return $this->returnResult(
779
            $result,
780
            "GET /api/v3.1/lists/{ID}/bounced",
781
            "Got bounced subscribers"
782
        );
783
    }
784
785
786
    /**
787
     * Gets all unsubscribed subscribers who have unsubscribed since the given date
788
     *
789
     * @param Int $listID
790
     * @param string $daysAgo The date to start getting subscribers from
0 ignored issues
show
Documentation introduced by
Should the type for parameter $daysAgo not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
791
     * @param int $page The page number to get
792
     * @param int $pageSize The number of records per page
793
     * @param string $sortByField ('EMAIL', 'NAME', 'DATE')
794
     * @param string $sortDirection ('ASC', 'DESC')
795
     *
796
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
797
     * {
798
     *     'ResultsOrderedBy' => The field the results are ordered by
799
     *     'OrderDirection' => The order direction
800
     *     'PageNumber' => The page number for the result set
801
     *     'PageSize' => The page size used
802
     *     'RecordsOnThisPage' => The number of records returned
803
     *     'TotalNumberOfRecords' => The total number of records available
804
     *     'NumberOfPages' => The total number of pages for this collection
805
     *     'Results' => array(
806
     *         {
807
     *             'EmailAddress' => The email address of the subscriber
808
     *             'Name' => The name of the subscriber
809
     *             'Date' => The date that the subscriber was unsubscribed from the list
810
     *             'State' => The current state of the subscriber, will be 'Unsubscribed'
811
     *             'CustomFields' => array (
812
     *                 {
813
     *                     'Key' => The personalisation tag of the custom field
814
     *                     'Value' => The value of the custom field for this subscriber
815
     *                 }
816
     *             )
817
     *         }
818
     *     )
819
     * }
820
     */
821 View Code Duplication
    public function getUnsubscribedSubscribers($listID, $daysAgo = 3650, $page = 1, $pageSize = 999, $sortByField = "DATE", $sortDirection = "DESC")
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...
822
    {
823
        //require_once '../../csrest_lists.php';
824
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
825
        $result = $wrap->get_unsubscribed_subscribers(
826
            date('Y-m-d', strtotime('-'.$daysAgo.' days')),
827
            $page,
828
            $pageSize,
829
            $sortByField,
830
            $sortDirection
831
        );
832
        return $this->returnResult(
833
            $result,
834
            "GET /api/v3.1/lists/{ID}/unsubscribed",
835
            "Got unsubscribed subscribers"
836
        );
837
    }
838
839
    /**
840
     * Gets all unsubscribed subscribers who have unsubscribed since the given date
841
     *
842
     * @param Int $listID
843
     * @param string $daysAgo The date to start getting subscribers from
0 ignored issues
show
Documentation introduced by
Should the type for parameter $daysAgo not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
844
     * @param int $page The page number to get
845
     * @param int $pageSize The number of records per page
846
     * @param string $sortByField ('EMAIL', 'NAME', 'DATE')
847
     * @param string $sortDirection ('ASC', 'DESC')
848
     *
849
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
850
     * {
851
     *     'ResultsOrderedBy' => The field the results are ordered by
852
     *     'OrderDirection' => The order direction
853
     *     'PageNumber' => The page number for the result set
854
     *     'PageSize' => The page size used
855
     *     'RecordsOnThisPage' => The number of records returned
856
     *     'TotalNumberOfRecords' => The total number of records available
857
     *     'NumberOfPages' => The total number of pages for this collection
858
     *     'Results' => array(
859
     *         {
860
     *             'EmailAddress' => The email address of the subscriber
861
     *             'Name' => The name of the subscriber
862
     *             'Date' => The date that the subscriber was unsubscribed from the list
863
     *             'State' => The current state of the subscriber, will be 'Unsubscribed'
864
     *             'CustomFields' => array (
865
     *                 {
866
     *                     'Key' => The personalisation tag of the custom field
867
     *                     'Value' => The value of the custom field for this subscriber
868
     *                 }
869
     *             )
870
     *         }
871
     *     )
872
     * }
873
     */
874
    public function getDeletedSubscribers($listID, $daysAgo = 3650, $page = 1, $pageSize = 999, $sortByField = "email", $sortDirection = "asc")
875
    {
876
        //require_once '../../csrest_lists.php';
877
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
878
        $result = $wrap->get_deleted_subscribers(
879
            date('Y-m-d', strtotime('-'.$daysAgo.' days')),
880
            $page,
881
            $pageSize,
882
            $sortByField,
883
            $sortDirection
884
        );
885
        return $this->returnResult(
886
            $result,
887
            "GET /api/v3/lists/{ID}/delete",
888
            "Got deleted subscribers"
889
        );
890
    }
891
892
    /**
893
     * Updates the details of an existing list
894
     * Both the UnsubscribePage and the ConfirmationSuccessPage parameters are optional
895
     *
896
     * @param string $title - he page to redirect subscribers to when they unsubscribeThe list title
897
     * @param string $unsubscribePage - The page to redirect subscribers to when they unsubscribe
898
     * @param boolean $confirmedOptIn - Whether this list requires confirmation of subscription
899
     * @param string $confirmationSuccessPage - The page to redirect subscribers to when they confirm their subscription
900
     * @param string $unsubscribeSetting - Unsubscribe setting must be CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS or CS_REST_LIST_UNSUBSCRIBE_SETTING_ONLY_THIS_LIST.  See the documentation for details: http://www.campaignmonitor.com/api/lists/#creating_a_list
901
     * @param boolean $addUnsubscribesToSuppList -  When UnsubscribeSetting is CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS, whether unsubscribes from this list should be added to the suppression list.
902
     * @param boolean $acrubActiveWithSuppList - When UnsubscribeSetting is CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS, whether active subscribers should be scrubbed against the suppression list.
0 ignored issues
show
Documentation introduced by
There is no parameter named $acrubActiveWithSuppList. Did you maybe mean $scrubActiveWithSuppList?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
903
     *
904
     * @return CS_REST_Wrapper_Result A successful response will be empty
905
     */
906
    public function updateList($listID, $title, $unsubscribePage, $confirmedOptIn = false, $confirmationSuccessPage, $unsubscribeSetting, $addUnsubscribesToSuppList = true, $scrubActiveWithSuppList = true)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
907
    {
908
        //require_once '../../csrest_lists.php';
909
        if (!$unsubscribeSetting) {
910
            $unsubscribeSetting = CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS;
911
        }
912
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
913
        $result = $wrap->update(array(
914
            'Title' => $title,
915
            'UnsubscribePage' => $unsubscribePage,
916
            'ConfirmedOptIn' => $confirmedOptIn,
917
            'ConfirmationSuccessPage' => $confirmationSuccessPage,
918
            'UnsubscribeSetting' => $unsubscribeSetting,
919
            'AddUnsubscribesToSuppList' => $addUnsubscribesToSuppList,
920
            'ScrubActiveWithSuppList' => $scrubActiveWithSuppList
921
        ));
922
        return $this->returnResult(
923
            $result,
924
            "PUT /api/v3.1/lists/{ID}",
925
            "Updated with code"
926
        );
927
    }
928
929 View Code Duplication
    public function getSegments($listID)
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...
930
    {
931
        //require_once '../../csrest_lists.php';
932
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
933
        //we need to do this afterwards otherwise the definition below
934
        //is not recognised
935
        $result = $wrap->get_segments();
936
        return $this->returnResult(
937
            $result,
938
            "GET /api/v3.1/lists/{listid}/segments",
939
            "Got segment details"
940
        );
941
    }
942
943
    /**
944
     * Gets statistics for list subscriptions, deletions, bounces and unsubscriptions
945
     *
946
     * @param Int $listID
947
     *
948
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
949
     * {
950
     *     'TotalActiveSubscribers'
951
     *     'NewActiveSubscribersToday'
952
     *     'NewActiveSubscribersYesterday'
953
     *     'NewActiveSubscribersThisWeek'
954
     *     'NewActiveSubscribersThisMonth'
955
     *     'NewActiveSubscribersThisYeay'
956
     *     'TotalUnsubscribes'
957
     *     'UnsubscribesToday'
958
     *     'UnsubscribesYesterday'
959
     *     'UnsubscribesThisWeek'
960
     *     'UnsubscribesThisMonth'
961
     *     'UnsubscribesThisYear'
962
     *     'TotalDeleted'
963
     *     'DeletedToday'
964
     *     'DeletedYesterday'
965
     *     'DeletedThisWeek'
966
     *     'DeletedThisMonth'
967
     *     'DeletedThisYear'
968
     *     'TotalBounces'
969
     *     'BouncesToday'
970
     *     'BouncesYesterday'
971
     *     'BouncesThisWeek'
972
     *     'BouncesThisMonth'
973
     *     'BouncesThisYear'
974
     * }
975
     */
976 View Code Duplication
    public function getListStats($listID)
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...
977
    {
978
        //require_once '../../csrest_lists.php';
979
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
980
        $result = $wrap->get_stats();
981
        return $this->returnResult(
982
            $result,
983
            "GET /api/v3.1/lists/{ID}/stats",
984
            "Got Lists Stats"
985
        );
986
    }
987
988 View Code Duplication
    public function getListCustomFields($listID)
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...
989
    {
990
        $wrap = new CS_REST_Lists($listID, $this->getAuth());
991
        $result = $wrap->get_custom_fields();
992
        return $this->returnResult(
993
            $result,
994
            "GET /api/v3.1/lists/{ID}/customfields",
995
            "Got Lists Custom Fields"
996
        );
997
    }
998
999
    /*******************************************************
1000
     * create campaigns
1001
     *
1002
     *******************************************************/
1003
1004
    /**
1005
     *
1006
     *
1007
     * @param CampaignMonitorCampaign $campaignMonitorCampaign
1008
     * @param array listIDs
1009
     * @param array segmentIDs
1010
     * @param string templateID - OPTIONAL!
1011
     * @param array templateContent - OPTIONAL!
1012
     */
1013
    public function createCampaign(
1014
        $campaignMonitorCampaign,
1015
        $listIDs = array(),
0 ignored issues
show
Unused Code introduced by
The parameter $listIDs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1016
        $segmentIDs = array(),
0 ignored issues
show
Unused Code introduced by
The parameter $segmentIDs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1017
        $templateID = "",
1018
        $templateContent = array()
1019
    ) {
1020
        //require_once '../../csrest_lists.php';
1021
        $siteConfig = SiteConfig::current_site_config();
1022
1023
        $subject = $campaignMonitorCampaign->Subject;
0 ignored issues
show
Documentation introduced by
The property Subject does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1024
        if (!$subject) {
1025
            $subject = "no subject set";
1026
        }
1027
1028
        $name = $campaignMonitorCampaign->Name;
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1029
        if (!$name) {
1030
            $name = "no name set";
1031
        }
1032
1033
        $fromName = $campaignMonitorCampaign->FromName;
0 ignored issues
show
Documentation introduced by
The property FromName does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1034
        if (!$fromName) {
1035
            $fromName = $siteConfig->Title;
1036
        }
1037
1038
        $fromEmail = $campaignMonitorCampaign->FromEmail;
0 ignored issues
show
Documentation introduced by
The property FromEmail does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1039
        if (!$fromEmail) {
1040
            $fromEmail = Config::inst()->get('Email', 'admin_email');
1041
        }
1042
1043
        $replyTo = $campaignMonitorCampaign->ReplyTo;
0 ignored issues
show
Documentation introduced by
The property ReplyTo does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1044
        if (!$replyTo) {
1045
            $replyTo = $fromEmail;
1046
        }
1047
1048
        $listID = $campaignMonitorCampaign->Pages()->first()->ListID;
0 ignored issues
show
Documentation Bug introduced by
The method Pages does not exist on object<CampaignMonitorCampaign>? 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...
1049
1050
        $wrap = new CS_REST_Campaigns(null, $this->getAuth());
1051
        if ($templateID) {
1052
            $result = $wrap->create_from_template(
1053
                $this->Config()->get("client_id"),
1054
                array(
1055
                    'Subject' => $subject,
1056
                    'Name' => $name,
1057
                    'FromName' => $fromName,
1058
                    'FromEmail' => $fromEmail,
1059
                    'ReplyTo' => $replyTo,
1060
                    'ListIDs' => array($listID),
1061
                    'SegmentIDs' => array(),
1062
                    'TemplateID' => $templateID,
1063
                    'TemplateContent' => $templateContent
1064
                )
1065
            );
1066
        } else {
1067
            $result = $wrap->create(
1068
                $this->Config()->get("client_id"),
1069
                array(
1070
                    'Subject' => $subject,
1071
                    'Name' => $name,
1072
                    'FromName' => $fromName,
1073
                    'FromEmail' => $fromEmail,
1074
                    'ReplyTo' => $replyTo,
1075
                    'HtmlUrl' => $campaignMonitorCampaign->PreviewLink(),
1076
                    'TextUrl' => $campaignMonitorCampaign->PreviewLink("textonly"),
1077
                    'ListIDs' => array($listID)
1078
                )
1079
            );
1080
        }
1081
        if (isset($result->http_status_code) && ($result->http_status_code == 201 || $result->http_status_code == 201)) {
1082
            $code = $result->response;
1083
            $campaignMonitorCampaign->CreateFromWebsite = false;
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1084
            $campaignMonitorCampaign->CreatedFromWebsite = true;
0 ignored issues
show
Bug introduced by
The property CreatedFromWebsite does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1085
            $campaignMonitorCampaign->CampaignID = $code;
0 ignored issues
show
Documentation introduced by
The property CampaignID does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1086
        } else {
1087
            $campaignMonitorCampaign->CreateFromWebsite = false;
0 ignored issues
show
Documentation introduced by
The property CreateFromWebsite does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1088
            $campaignMonitorCampaign->CreatedFromWebsite = false;
0 ignored issues
show
Bug introduced by
The property CreatedFromWebsite does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1089
            $code = "Error";
1090
            if (is_object($result->response)) {
1091
                $code = $result->response->Code.":".$result->response->Message;
1092
            }
1093
            $campaignMonitorCampaign->MessageFromNewsletterServer = $code;
0 ignored issues
show
Documentation introduced by
The property MessageFromNewsletterServer does not exist on object<CampaignMonitorCampaign>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1094
        }
1095
        $campaignMonitorCampaign->write();
1096
        return $this->returnResult(
1097
            $result,
1098
            "CREATE /api/v3/campaigns/{clientID}",
1099
            "Created Campaign"
1100
        );
1101
    }
1102
1103 View Code Duplication
    public function deleteCampaign($campaignID)
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...
1104
    {
1105
        $wrap = new CS_REST_Campaigns($campaignID, $this->getAuth());
1106
        $result = $wrap->delete();
1107
        return $this->returnResult(
1108
            $result,
1109
            "DELETE /api/v3/campaigns/{id}",
1110
            "Deleted Campaign"
1111
        );
1112
    }
1113
1114
    /*******************************************************
1115
     * information about the campaigns
1116
     *
1117
     *******************************************************/
1118
1119
    public function getBounces()
1120
    {
1121
        user_error("This method is still to be implemented, see samples for an example");
1122
    }
1123
1124
    public function getClicks()
1125
    {
1126
        user_error("This method is still to be implemented, see samples for an example");
1127
    }
1128
1129
    /**
1130
     * Gets a summary of all campaign reporting statistics
1131
     *
1132
     * @param int $campaignID
1133
     *
1134
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
1135
     * {
1136
     *     'Recipients' => The total recipients of the campaign
1137
     *     'TotalOpened' => The total number of opens recorded
1138
     *     'Clicks' => The total number of recorded clicks
1139
     *     'Unsubscribed' => The number of recipients who unsubscribed
1140
     *     'Bounced' => The number of recipients who bounced
1141
     *     'UniqueOpened' => The number of recipients who opened
1142
     *     'WebVersionURL' => The url of the web version of the campaign
1143
     *     'WebVersionTextURL' => The url of the web version of the text version of the campaign
1144
     *     'WorldviewURL' => The public Worldview URL for the campaign
1145
     *     'Forwards' => The number of times the campaign has been forwarded to a friend
1146
     *     'Likes' => The number of times the campaign has been 'liked' on Facebook
1147
     *     'Mentions' => The number of times the campaign has been tweeted about
1148
     *     'SpamComplaints' => The number of recipients who marked the campaign as spam
1149
     * }
1150
     */
1151 View Code Duplication
    public function getSummary($campaignID)
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...
1152
    {
1153
        $wrap = new CS_REST_Campaigns($campaignID, $this->getAuth());
1154
        $result = $wrap->get_summary();
1155
        return $this->returnResult(
1156
            $result,
1157
            "GET /api/v3.1/campaigns/{id}/summary",
1158
            "Got Summary"
1159
        );
1160
    }
1161
1162
    /**
1163
     * Gets the email clients that subscribers used to open the campaign
1164
     *
1165
     * @param Int $campaignID
1166
     *
1167
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
1168
     * array(
1169
     *     {
1170
     *         Client => The email client name
1171
     *         Version => The email client version
1172
     *         Percentage => The percentage of subscribers who used this email client
1173
     *         Subscribers => The actual number of subscribers who used this email client
1174
     *     }
1175
     * )
1176
     */
1177 View Code Duplication
    public function getEmailClientUsage($campaignID)
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...
1178
    {
1179
        $wrap = new CS_REST_Campaigns($campaignID, $this->getAuth());
1180
        $result = $wrap->get_email_client_usage();
1181
        return $this->returnResult(
1182
            $result,
1183
            "GET /api/v3.1/campaigns/{id}/emailclientusage",
1184
            "Got email client usage"
1185
        );
1186
    }
1187
1188
    public function getListsAndSegments()
1189
    {
1190
        user_error("This method is still to be implemented, see samples for an example");
1191
    }
1192
1193
    public function getOpens()
1194
    {
1195
        user_error("This method is still to be implemented, see samples for an example");
1196
    }
1197
1198
    public function getRecipients()
1199
    {
1200
        user_error("This method is still to be implemented, see samples for an example");
1201
    }
1202
1203
    public function getSpam()
1204
    {
1205
        user_error("This method is still to be implemented, see samples for an example");
1206
    }
1207
1208
    /**
1209
     * Gets all unsubscribes recorded for a campaign since the provided date
1210
     *
1211
     * @param int $campaignID ID of the Campaign
1212
     * @param string $daysAgo The date to start getting subscribers from
0 ignored issues
show
Documentation introduced by
Should the type for parameter $daysAgo not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1213
     * @param int $page The page number to get
1214
     * @param int $pageSize The number of records per page
1215
     * @param string $sortByField ('EMAIL', 'NAME', 'DATE')
1216
     * @param string $sortDirection ('ASC', 'DESC')
1217
     *
1218
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
1219
     * {
1220
     *     'ResultsOrderedBy' => The field the results are ordered by
1221
     *     'OrderDirection' => The order direction
1222
     *     'PageNumber' => The page number for the result set
1223
     *     'PageSize' => The page size used
1224
     *     'RecordsOnThisPage' => The number of records returned
1225
     *     'TotalNumberOfRecords' => The total number of records available
1226
     *     'NumberOfPages' => The total number of pages for this collection
1227
     *     'Results' => array(
1228
     *         {
1229
     *             'EmailAddress' => The email address of the subscriber who unsubscribed
1230
     *             'ListID' => The list id of the list containing the subscriber
1231
     *             'Date' => The date of the unsubscribe
1232
     *             'IPAddress' => The ip address where the unsubscribe originated
1233
     *         }
1234
     *     )
1235
     * }
1236
     */
1237 View Code Duplication
    public function getUnsubscribes($campaignID, $daysAgo = 3650, $page =1, $pageSize = 999, $sortByField = "EMAIL", $sortDirection = "ASC")
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...
1238
    {
1239
        //require_once '../../csrest_campaigns.php';
1240
        $wrap = new CS_REST_Campaigns($campaignID, $this->getAuth());
1241
        $result = $wrap->get_unsubscribes(
1242
            date('Y-m-d', strtotime('-'.$daysAgo.' days')),
1243
            $page,
1244
            $pageSize,
1245
            $sortByField,
1246
            $sortDirection
1247
        );
1248
        return $this->returnResult(
1249
            $result,
1250
            "GET /api/v3.1/campaigns/{id}/unsubscribes",
1251
            "Got unsubscribes"
1252
        );
1253
    }
1254
1255
1256
1257
    /*******************************************************
1258
     * user
1259
     *
1260
     * states:
1261
     *
1262
     * Active – Someone who is on a list and will receive any emails sent to that list.
1263
     *
1264
     * Unconfirmed – The individual signed up to a confirmed opt-in list
1265
     * but has not clicked the link in the verification email sent to them.
1266
     *
1267
     * Unsubscribed – The subscriber has removed themselves from a list, or lists,
1268
     * via an unsubscribe link or form.
1269
     * You can also change a subscriber's status to unsubscribed through your account.
1270
     *
1271
     * Bounced – This describes an email address that campaigns cannot be delivered to,
1272
     * which can happen for a number of reasons.
1273
     *
1274
     * Deleted – Means the subscriber has been deleted from a list through your account.
1275
     *
1276
     *******************************************************/
1277
1278
    /**
1279
     * Gets the lists across a client to which a subscriber with a particular
1280
     * email address belongs.
1281
     *
1282
     * @param string | Member $email Subscriber's email address (or Member)
1283
     *
1284
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
1285
     * array(
1286
     *     {
1287
     *         'ListID' => The id of the list
1288
     *         'ListName' => The name of the list
1289
     *         'SubscriberState' => The state of the subscriber in the list
1290
     *         'DateSubscriberAdded' => The date the subscriber was added
1291
     *     }
1292
     * )
1293
     */
1294
    public function getListsForEmail($member)
1295
    {
1296
        if ($member instanceof Member) {
1297
            $member = $member->Email;
1298
        }
1299
        //require_once '../../csrest_clients.php';
1300
        $wrap = new CS_REST_Clients($this->Config()->get("client_id"), $this->getAuth());
1301
        $result = $wrap->get_lists_for_email($member);
1302
        return $this->returnResult(
1303
            $result,
1304
            "/api/v3.1/clients/{id}/listsforemail",
1305
            "Got lists to which email address ".$member." is subscribed"
1306
        );
1307
    }
1308
1309
1310
    /**
1311
     * Adds a new subscriber to the specified list
1312
     *
1313
     * @param Int $listID
1314
     * @param Member $member
1315
     * @param Array $customFields
1316
     * @param array $customFields The subscriber details to use during creation.
1317
     * @param boolean $resubscribe Whether we should resubscribe this subscriber if they already exist in the list
1318
     * @param boolean $RestartSubscriptionBasedAutoResponders Whether we should restart subscription based auto responders which are sent when the subscriber first subscribes to a list.
0 ignored issues
show
Documentation introduced by
There is no parameter named $RestartSubscriptionBasedAutoResponders. Did you maybe mean $restartSubscriptionBasedAutoResponders?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
1319
     *
1320
     * NOTE that for the custom fields they need to be formatted like this:
1321
     *    Array(
1322
     *        'Key' => The custom fields personalisation tag
1323
     *        'Value' => The value for this subscriber
1324
     *        'Clear' => true/false (pass true to remove this custom field. in the case of a [multi-option, select many] field, pass an option in the 'Value' field to clear that option or leave Value blank to remove all options)
1325
     *    )
1326
     *
1327
     * @return CS_REST_Wrapper_Result A successful response will be empty
1328
     */
1329
    public function addSubscriber(
1330
        $listID,
1331
        $member,
1332
        $customFields = array(),
1333
        $resubscribe = true,
1334
        $restartSubscriptionBasedAutoResponders = false
1335
    ) {
1336
        //require_once '../../csrest_subscribers.php';
1337
        $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1338 View Code Duplication
        foreach ($customFields as $key => $customFieldValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
1339
            if (!is_array($customFields[$key])) {
1340
                $customFields[] = array(
1341
                    "Key" => $key,
1342
                    "Value" => $customFieldValue,
1343
                    "Clear" => $customFieldValue ? false : true
1344
                );
1345
                unset($customFields[$key]);
1346
            }
1347
        }
1348
        $result = $wrap->add(
1349
            $request = array(
1350
                'EmailAddress' => $member->Email,
1351
                'Name' => $member->getName(),
1352
                'CustomFields' => $customFields,
1353
                'Resubscribe' => $resubscribe,
1354
                'RestartSubscriptionBasedAutoResponders' => $restartSubscriptionBasedAutoResponders
1355
            )
1356
        );
1357
        return $this->returnResult(
1358
            $result,
1359
            "POST /api/v3.1/subscribers/{list id}.{format}",
1360
            "Subscribed with code ..."
1361
        );
1362
    }
1363
1364
    /**
1365
     * Updates an existing subscriber (email, name, state, or custom fields) in the specified list.
1366
     * The update is performed even for inactive subscribers, but will return an error in the event of the
1367
     * given email not existing in the list.
1368
     *
1369
     * @param Int $listID
1370
     * @param String $oldEmailAddress
1371
     * @param Member $member
1372
     * @param array $customFields The subscriber details to use during creation.
1373
     * @param boolean $resubscribe Whether we should resubscribe this subscriber if they already exist in the list
1374
     * @param boolean $restartSubscriptionBasedAutoResponders Whether we should restart subscription based auto responders which are sent when the subscriber first subscribes to a list.
1375
     *
1376
     * NOTE that for the custom fields they need to be formatted like this:
1377
     *    Array(
1378
     *        'Key' => The custom fields personalisation tag
1379
     *        'Value' => The value for this subscriber
1380
     *        'Clear' => true/false (pass true to remove this custom field. in the case of a [multi-option, select many] field, pass an option in the 'Value' field to clear that option or leave Value blank to remove all options)
1381
     *    )
1382
     *
1383
     * @return CS_REST_Wrapper_Result A successful response will be empty
1384
     */
1385
    public function updateSubscriber(
1386
        $listID,
1387
        $oldEmailAddress = "",
1388
        Member $member,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
1389
        $customFields = array(),
1390
        $resubscribe = true,
1391
        $restartSubscriptionBasedAutoResponders = false
1392
    ) {
1393
        if (!$oldEmailAddress) {
1394
            $oldEmailAddress = $member->Email;
1395
        }
1396 View Code Duplication
        foreach ($customFields as $key => $customFieldValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
1397
            if (!is_array($customFields[$key])) {
1398
                $customFields[] = array(
1399
                    "Key" => $key,
1400
                    "Value" => $customFieldValue,
1401
                    "Clear" => $customFieldValue ? false : true
1402
                );
1403
                unset($customFields[$key]);
1404
            }
1405
        }
1406
        //require_once '../../csrest_subscribers.php';
1407
        $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1408
        $result = $wrap->update(
1409
            $oldEmailAddress,
0 ignored issues
show
Bug introduced by
It seems like $oldEmailAddress defined by $member->Email on line 1394 can also be of type array; however, CS_REST_Subscribers::update() does only seem to accept string, 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...
1410
            array(
1411
                'EmailAddress' => $member->Email,
1412
                'Name' => $member->getName(),
1413
                'CustomFields' => $customFields,
1414
                'Resubscribe' => $resubscribe,
1415
                'RestartSubscriptionBasedAutoResponders' => $restartSubscriptionBasedAutoResponders,
1416
            )
1417
        );
1418
        return $this->returnResult(
1419
            $result,
1420
            "PUT /api/v3.1/subscribers/{list id}.{format}?email={email}",
1421
            "updated with email $oldEmailAddress ..."
1422
        );
1423
    }
1424
1425
    /**
1426
     * Updates an existing subscriber (email, name, state, or custom fields) in the specified list.
1427
     * The update is performed even for inactive subscribers, but will return an error in the event of the
1428
     * given email not existing in the list.
1429
     *
1430
     * @param Int $listID
1431
     * @param ArraySet $memberSet - list of mebers
0 ignored issues
show
Documentation introduced by
There is no parameter named $memberSet. Did you maybe mean $membersSet?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
1432
     * @param array $customFields The subscriber details to use during creation. Each array item needs to have the same key as the member ID - e.g. array( 123 => array( [custom fields here] ), 456 => array( [custom fields here] ) )
1433
     * @param $resubscribe Whether we should resubscribe any existing subscribers
1434
     * @param $queueSubscriptionBasedAutoResponders By default, subscription based auto responders do not trigger during an import. Pass a value of true to override this behaviour
1435
     * @param $restartSubscriptionBasedAutoResponders By default, subscription based auto responders will not be restarted
1436
     *
1437
     * NOTE that for the custom fields they need to be formatted like this:
1438
     *    Array(
1439
     *        'Key' => The custom fields personalisation tag
1440
     *        'Value' => The value for this subscriber
1441
     *        'Clear' => true/false (pass true to remove this custom field. in the case of a [multi-option, select many] field, pass an option in the 'Value' field to clear that option or leave Value blank to remove all options)
1442
     *    )
1443
1444
     * @return CS_REST_Wrapper_Result A successful response will be empty
1445
     */
1446
    public function addSubscribers(
1447
        $listID,
1448
        $membersSet,
1449
        $customFields = array(),
1450
        $resubscribe,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
1451
        $queueSubscriptionBasedAutoResponders = false,
1452
        $restartSubscriptionBasedAutoResponders = false
1453
    ) {
1454
        //require_once '../../csrest_subscribers.php';
1455
        $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1456
        $importArray = array();
1457
        foreach ($membersSet as $member) {
1458
            $customFieldsForMember = array();
1459
            if (isset($customFields[$member->ID])) {
1460
                $customFieldsForMember = $customFields[$member->ID];
1461
            } elseif (isset($customFields[$member->Email])) {
1462
                $customFieldsForMember = $customFields[$member->Email];
1463
            }
1464 View Code Duplication
            foreach ($customFieldsForMember as $key => $customFieldValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
1465
                if (!is_array($customFieldsForMember[$key])) {
1466
                    $customFieldsForMember[] = array(
1467
                        "Key" => $key,
1468
                        "Value" => $customFieldValue,
1469
                        "Clear" => $customFieldValue ? false : true
1470
                    );
1471
                    unset($customFieldsForMember[$key]);
1472
                }
1473
            }
1474
            if ($member instanceof Member) {
1475
                $importArray[] = array(
1476
                    'EmailAddress' => $member->Email,
1477
                    'Name' => $member->getName(),
1478
                    'CustomFields' => $customFieldsForMember
1479
                );
1480
            }
1481
        }
1482
        $result = $wrap->import(
1483
            $importArray,
1484
            $resubscribe,
1485
            $queueSubscriptionBasedAutoResponders,
1486
            $restartSubscriptionBasedAutoResponders
1487
        );
1488
        return $this->returnResult(
1489
            $result,
1490
            "POST /api/v3.1/subscribers/{list id}/import.{format}",
1491
            "review details ..."
1492
        );
1493
    }
1494
1495
    /**
1496
     * @param Int $listID
1497
     * @param Member | String $member - email address or Member Object
1498
     *
1499
     * @return CS_REST_Wrapper_Result A successful response will be empty
1500
     */
1501 View Code Duplication
    public function deleteSubscriber($listID, $member)
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...
1502
    {
1503
        if ($member instanceof Member) {
1504
            $member = $member->Email;
1505
        }
1506
        $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1507
        $result = $wrap->delete($member);
1508
        return $this->returnResult(
1509
            $result,
1510
            "DELETE /api/v3.1/subscribers/{list id}.{format}?email={emailAddress}",
1511
            "Unsubscribed with code  ..."
1512
        );
1513
    }
1514
1515
    /**
1516
     * Unsubscribes the given subscriber from the current list
1517
     *
1518
     * @param Int $listID
1519
     * @param Member | String $member
1520
     *
1521
     * @return CS_REST_Wrapper_Result A successful response will be empty
1522
     */
1523 View Code Duplication
    public function unsubscribeSubscriber($listID, $member)
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...
1524
    {
1525
        if ($member instanceof Member) {
1526
            $member = $member->Email;
1527
        }
1528
        $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1529
        $result = $wrap->unsubscribe($member);
1530
        return $this->returnResult(
1531
            $result,
1532
            "GET /api/v3.1/subscribers/{list id}/unsubscribe.{format}",
1533
            "Unsubscribed with code  ..."
1534
        );
1535
    }
1536
1537
    /**
1538
     * Is this user part of this list at all?
1539
     *
1540
     * @param Int $listID
1541
     * @param Member | String $member
1542
     *
1543
     * @return Boolean
1544
     */
1545 View Code Duplication
    public function getSubscriberExistsForThisList($listID, $member)
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...
1546
    {
1547
        if ($member instanceof Member) {
1548
            $member = $member->Email;
1549
        }
1550
        $outcome = $this->getSubscriber($listID, $member);
1551
        if ($outcome && isset($outcome->State)) {
1552
            if ($this->debug) {
1553
                echo "<h3>Subscriber Exists For This List</h3>";
1554
            }
1555
            return true;
1556
        }
1557
        if ($this->debug) {
1558
            echo "<h3>Subscriber does *** NOT *** Exist For This List</h3>";
1559
        }
1560
        return false;
1561
    }
1562
1563
    /**
1564
     * Can we send e-mails to this person in the future for this list?
1565
     *
1566
     * @param Int $listID
1567
     * @param Member | String $member
1568
     *
1569
     * @return Boolean
1570
     */
1571 View Code Duplication
    public function getSubscriberCanReceiveEmailsForThisList($listID, $member)
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...
1572
    {
1573
        if ($member instanceof Member) {
1574
            $member = $member->Email;
1575
        }
1576
        $outcome = $this->getSubscriber($listID, $member);
1577
        if ($outcome && isset($outcome->State)) {
1578
            if ($outcome->State == "Active") {
0 ignored issues
show
Bug introduced by
The property State does not seem to exist in CS_REST_Wrapper_Result.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1579
                if ($this->debug) {
1580
                    echo "<h3>Subscriber Can Receive Emails For This List</h3>";
1581
                }
1582
                return true;
1583
            }
1584
        }
1585
        if ($this->debug) {
1586
            echo "<h3>Subscriber Can *** NOT *** Receive Emails For This List</h3>";
1587
        }
1588
        return false;
1589
    }
1590
1591
    /**
1592
     * This e-mail / user has been banned from a list.
1593
     *
1594
     * @param Int $listID
1595
     * @param Member | String $member
1596
     *
1597
     * @return Boolean
1598
     */
1599
    public function getSubscriberCanNoLongerReceiveEmailsForThisList($listID, $member)
1600
    {
1601
        $subscriberExistsForThisList = $this->getSubscriberExistsForThisList($listID, $member);
1602
        $subscriberCanReceiveEmailsForThisList = $this->getSubscriberCanReceiveEmailsForThisList($listID, $member);
1603
        if ($subscriberExistsForThisList) {
1604
            if (!$subscriberCanReceiveEmailsForThisList) {
1605
                if ($this->debug) {
1606
                    echo "<h3>Subscriber Can No Longer Receive Emails For This List</h3>";
1607
                }
1608
                return true;
1609
            }
1610
        }
1611
        if ($this->debug) {
1612
            echo "<h3>Subscriber Can *** STILL *** Receive Emails For This List</h3>";
1613
        }
1614
        return false;
1615
    }
1616
1617
    private static $_get_subscriber = array();
1618
1619
    /**
1620
     * Gets a subscriber details, including custom fields
1621
     *
1622
     * @param Int $listID
1623
     * @param Member | String $member
1624
     *
1625
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
1626
     * {
1627
     *     'EmailAddress' => The subscriber email address
1628
     *     'Name' => The subscribers name
1629
     *     'Date' => The date the subscriber was added to the list
1630
     *     'State' => The current state of the subscriber
1631
     *     'CustomFields' => array(
1632
     *         {
1633
     *             'Key' => The custom fields personalisation tag
1634
     *             'Value' => The custom field value for this subscriber
1635
     *         }
1636
     *     )
1637
     * }
1638
     *
1639
     */
1640
    public function getSubscriber($listID, $member, $cacheIsOK = true)
1641
    {
1642
        if ($member instanceof Member) {
1643
            $member = $member->Email;
1644
        }
1645
        $key = $listID."_".$member;
1646
        if (isset(self::$_get_subscriber[$key]) && $cacheIsOK) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1647
            //do nothing
1648
        } else {
1649
            $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1650
            $result = $wrap->get($member);
1651
            self::$_get_subscriber[$key] = $this->returnResult(
1652
                $result,
1653
                "GET /api/v3.1/subscribers/{list id}.{format}?email={email}",
1654
                "got subscribed subscriber"
1655
            );
1656
        }
1657
        return self::$_get_subscriber[$key];
1658
    }
1659
1660
    /**
1661
     * Gets a subscriber details, including custom fields
1662
     *
1663
     * @param Int $listID
1664
     * @param Member | String $member
1665
     *
1666
     * @return CS_REST_Wrapper_Result A successful response will be an object of the form
1667
     * {
1668
     *     'EmailAddress' => The subscriber email address
1669
     *     'Name' => The subscribers name
1670
     *     'Date' => The date the subscriber was added to the list
1671
     *     'State' => The current state of the subscriber
1672
     *     'CustomFields' => array(
1673
     *         {
1674
     *             'Key' => The custom fields personalisation tag
1675
     *             'Value' => The custom field value for this subscriber
1676
     *         }
1677
     *     )
1678
     * }
1679
     *
1680
     */
1681 View Code Duplication
    public function getHistory($listID, $member)
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...
1682
    {
1683
        if ($member instanceof Member) {
1684
            $member = $member->Email;
1685
        }
1686
        $wrap = new CS_REST_Subscribers($listID, $this->getAuth());
1687
        $result = $wrap->get_history($member);
1688
        return $this->returnResult(
1689
            $result,
1690
            "GET /api/v3.1/subscribers/{list id}/history.{format}?email={email}",
1691
            "got subscriber history"
1692
        );
1693
    }
1694
}
1695