Issues (407)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/actions/twitter/twitter.php (139 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Twitter class
5
 *
6
 * This source file can be used to communicate with Twitter (http://twitter.com)
7
 *
8
 * The class is documented in the file itself. If you find any bugs help me out and report them. Reporting can be done by sending an email to php-twitter-bugs[at]verkoyen[dot]eu.
9
 * If you report a bug, make sure you give me enough information (include your code).
10
 *
11
 * Known Issues
12
 *  - savedSearchesDestroy isn't working correctly
13
 *  - trendsLocation isn't working correctly
14
 *  - oAuthAuthenticate isn't working correctly
15
 *  - accountUpdateProfileImage isn't implemented
16
 *  - accountUpdateProfileBackgroundImage isn't implemented
17
 *  - helpTest isn't working correctly
18
 *
19
 * Changelog since 2.0.0
20
 * - no more fatal if twitter is over capacity
21
 * - fix for calculating the header-string (thx to Dextro)
22
 * - fix for userListsIdStatuses (thx to Josh)
23
 * -
24
 *
25
 * License
26
 * Copyright (c) 2010, Tijs Verkoyen. All rights reserved.
27
 *
28
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29
 *
30
 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
31
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
32
 * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
33
 *
34
 * This software is provided by the author "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the author be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
35
 *
36
 * @author         Tijs Verkoyen <[email protected]>
37
 * @version        2.0.1
38
 *
39
 * @copyright      Copyright (c) 2010, Tijs Verkoyen. All rights reserved.
40
 * @license        BSD License
41
 */
42
class Twitter
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Twitter has been defined more than once; this definition is ignored, only the first definition in plugins/actions/twitter/Twitter.class.php (L12-75) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
43
{
44
    // internal constant to enable/disable debugging
45
    const DEBUG = false;
46
47
    // url for the twitter-api
48
    const API_URL        = 'https://api.twitter.com/1';
49
    const SECURE_API_URL = 'https://api.twitter.com';
50
51
    // port for the twitter-api
52
    const API_PORT        = 443;
53
    const SECURE_API_PORT = 443;
54
55
    // current version
56
    const VERSION = '2.0.1';
57
58
    /**
59
     * A cURL instance
60
     *
61
     * @var    resource
62
     */
63
    private $curl;
64
65
    /**
66
     * The consumer key
67
     *
68
     * @var    string
69
     */
70
    private $consumerKey;
71
72
    /**
73
     * The consumer secret
74
     *
75
     * @var    string
76
     */
77
    private $consumerSecret;
78
79
    /**
80
     * The oAuth-token
81
     *
82
     * @var    string
83
     */
84
    private $oAuthToken = '';
85
86
    /**
87
     * The oAuth-token-secret
88
     *
89
     * @var    string
90
     */
91
    private $oAuthTokenSecret = '';
92
93
    /**
94
     * The timeout
95
     *
96
     * @var    int
97
     */
98
    private $timeOut = 60;
99
100
    /**
101
     * The user agent
102
     *
103
     * @var    string
104
     */
105
    private $userAgent;
106
107
    // class methods
108
    /**
109
     * Default constructor
110
     *
111
     *
112
     * @param    string $consumerKey    The consumer key to use.
113
     * @param    string $consumerSecret The consumer secret to use.
114
     */
115
    public function __construct($consumerKey, $consumerSecret)
116
    {
117
        $this->setConsumerKey($consumerKey);
0 ignored issues
show
The method setConsumerKey() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
118
        $this->setConsumerSecret($consumerSecret);
0 ignored issues
show
The method setConsumerSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
    }
120
121
    /**
122
     * Default destructor
123
     *
124
     * @return    void
125
     */
126
    public function __destruct()
127
    {
128
        if ($this->curl != null) curl_close($this->curl);
0 ignored issues
show
The property curl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
129
    }
130
131
    /**
132
     * Format the parameters as a querystring
133
     *
134
     * @return    string
135
     * @param    array $parameters
136
     */
137
    private function buildQuery(array $parameters)
138
    {
139
        // no parameters?
140
        if (empty($parameters)) return '';
141
142
        // encode the keys
143
        $keys = self::urlencode_rfc3986(array_keys($parameters));
0 ignored issues
show
The method urlencode_rfc3986() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
145
        // encode the values
146
        $values = self::urlencode_rfc3986(array_values($parameters));
0 ignored issues
show
The method urlencode_rfc3986() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
148
        // reset the parameters
149
        $parameters = array_combine($keys, $values);
150
151
        // sort parameters by key
152
        uksort($parameters, 'strcmp');
153
154
        // loop parameters
155
        foreach ($parameters as $key => $value) {
156
            // sort by value
157
            if (is_array($value)) $parameters[$key] = natsort($value);
158
        }
159
160
        // process parameters
161
        foreach ($parameters as $key => $value) $chunks[] = $key . '=' . str_replace('%25', '%', $value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$chunks was never initialized. Although not strictly required by PHP, it is generally a good practice to add $chunks = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
162
163
        // return
164
        return implode('&', $chunks);
0 ignored issues
show
The variable $chunks 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...
165
    }
166
167
    /**
168
     * All OAuth 1.0 requests use the same basic algorithm for creating a signature base string and a signature.
169
     * The signature base string is composed of the HTTP method being used, followed by an ampersand ("&") and then the URL-encoded base URL being accessed,
170
     * complete with path (but not query parameters), followed by an ampersand ("&").
171
     * Then, you take all query parameters and POST body parameters (when the POST body is of the URL-encoded type, otherwise the POST body is ignored),
172
     * including the OAuth parameters necessary for negotiation with the request at hand, and sort them in lexicographical order by first parameter name and
173
     * then parameter value (for duplicate parameters), all the while ensuring that both the key and the value for each parameter are URL encoded in isolation.
174
     * Instead of using the equals ("=") sign to mark the key/value relationship, you use the URL-encoded form of "%3D". Each parameter is then joined by the
175
     * URL-escaped ampersand sign, "%26".
176
     *
177
     * @return    string
178
     * @param    string $url
179
     * @param    string $method
180
     * @param    array  $parameters
181
     */
182
    private function calculateBaseString($url, $method, array $parameters)
183
    {
184
        // redefine
185
        $url        = (string)$url;
186
        $parameters = (array)$parameters;
187
188
        // init var
189
        $pairs  = array();
0 ignored issues
show
$pairs 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...
190
        $chunks = array();
191
192
        // sort parameters by key
193
        uksort($parameters, 'strcmp');
194
195
        // loop parameters
196
        foreach ($parameters as $key => $value) {
197
            // sort by value
198
            if (is_array($value)) $parameters[$key] = natsort($value);
199
        }
200
201
        // process queries
202
        foreach ($parameters as $key => $value) {
203
            $chunks[] = self::urlencode_rfc3986($key) . '%3D' . self::urlencode_rfc3986($value);
0 ignored issues
show
The method urlencode_rfc3986() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
204
        }
205
206
        // buils base
207
        $base = $method . '&';
208
        $base .= urlencode($url) . '&';
209
        $base .= implode('%26', $chunks);
210
211
        // return
212
        return $base;
213
    }
214
215
    /**
216
     * Build the Authorization header
217
     * @later: fix me
218
     *
219
     *
220
     * @param    array $parameters
221
     * @param null     $url
222
     * @return string
223
     */
224
    private function calculateHeader(array $parameters, $url = null)
225
    {
226
        // redefine
227
        $url = (string)$url;
228
229
        // divide into parts
230
        $parts = parse_url($url);
231
232
        // init var
233
        $chunks = array();
234
235
        // process queries
236
        foreach ($parameters as $key => $value) $chunks[] = str_replace('%25', '%', self::urlencode_rfc3986($key) . '="' . self::urlencode_rfc3986($value) . '"');
0 ignored issues
show
The method urlencode_rfc3986() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
237
238
        // build return
239
        $return = 'Authorization: OAuth realm="' . $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '", ';
240
        $return .= implode(',', $chunks);
241
242
        // prepend name and OAuth part
243
        return $return;
244
    }
245
246
    /**
247
     * Make an call to the oAuth
248
     * @todo    refactor me
249
     *
250
     *
251
     * @param    string $method
252
     * @param array     $parameters [optional] $parameters
253
     * @return array
254
     * @throws TwitterException
255
     */
256
    private function doOAuthCall($method, array $parameters = null)
257
    {
258
        // redefine
259
        $method = (string)$method;
260
261
        // append default parameters
262
        $parameters['oauth_consumer_key']     = $this->getConsumerKey();
0 ignored issues
show
The method getConsumerKey() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
263
        $parameters['oauth_nonce']            = md5(microtime() . rand());
264
        $parameters['oauth_timestamp']        = time();
265
        $parameters['oauth_signature_method'] = 'HMAC-SHA1';
266
        $parameters['oauth_version']          = '1.0';
267
268
        // calculate the base string
269
        $base = $this->calculateBaseString(self::SECURE_API_URL . '/oauth/' . $method, 'POST', $parameters);
0 ignored issues
show
The method calculateBaseString() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
270
271
        // add sign into the parameters
272
        $parameters['oauth_signature'] = $this->hmacsha1($this->getConsumerSecret() . '&' . $this->getOAuthTokenSecret(), $base);
0 ignored issues
show
The method getConsumerSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method getOAuthTokenSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method hmacsha1() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
273
274
        // calculate header
275
        $header = $this->calculateHeader($parameters, self::SECURE_API_URL . '/oauth/' . $method);
0 ignored issues
show
The method calculateHeader() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
$header 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...
276
277
        // set options
278
        $options[CURLOPT_URL]            = self::SECURE_API_URL . '/oauth/' . $method;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
279
        $options[CURLOPT_PORT]           = self::SECURE_API_PORT;
280
        $options[CURLOPT_USERAGENT]      = $this->getUserAgent();
0 ignored issues
show
The method getUserAgent() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
281
        $options[CURLOPT_FOLLOWLOCATION] = true;
282
        $options[CURLOPT_RETURNTRANSFER] = true;
283
        $options[CURLOPT_TIMEOUT]        = (int)$this->getTimeOut();
0 ignored issues
show
The method getTimeOut() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
284
        $options[CURLOPT_SSL_VERIFYPEER] = false;
285
        $options[CURLOPT_SSL_VERIFYHOST] = false;
286
        $options[CURLOPT_HTTPHEADER]     = array('Expect:');
287
        $options[CURLOPT_POST]           = 1;
288
        $options[CURLOPT_POSTFIELDS]     = $this->buildQuery($parameters);
0 ignored issues
show
The method buildQuery() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
289
290
        // init
291
        if ($this->curl == null) $this->curl = curl_init();
292
293
        // set options
294
        curl_setopt_array($this->curl, $options);
295
296
        // execute
297
        $response = curl_exec($this->curl);
298
        $headers  = curl_getinfo($this->curl);
0 ignored issues
show
$headers 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...
299
300
        // fetch errors
301
        $errorNumber  = curl_errno($this->curl);
302
        $errorMessage = curl_error($this->curl);
303
304
        // error?
305
        if ($errorNumber != '') throw new TwitterException($errorMessage, $errorNumber);
306
307
        // init var
308
        $return = array();
309
310
        // parse the string
311
        parse_str($response, $return);
312
313
        // return
314
        return $return;
315
    }
316
317
    /**
318
     * Make the call
319
     *
320
     *
321
     * @param    string $url
322
     * @param array     $parameters
323
     * @param bool      $authenticate
324
     * @param string    $method
325
     * @param null      $filePath
326
     * @param bool      $expectJSON
327
     * @return string
328
     * @throws TwitterException
329
     * @internal param $array [optiona] $aParameters
330
     * @internal param $bool [optional] $authenticate
331
     * @internal param $bool [optional] $usePost
332
     */
333
    private function doCall($url, array $parameters = null, $authenticate = false, $method = 'GET', $filePath = null, $expectJSON = true)
334
    {
335
        // allowed methods
336
        $allowedMethods = array('GET', 'POST');
337
338
        // redefine
339
        $url          = (string)$url;
340
        $parameters   = (array)$parameters;
341
        $authenticate = (bool)$authenticate;
0 ignored issues
show
$authenticate 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...
342
        $method       = (string)$method;
343
        $expectJSON   = (bool)$expectJSON;
344
345
        // validate method
346
        if (!in_array($method, $allowedMethods)) throw new TwitterException('Unknown method (' . $method . '). Allowed methods are: ' . implode(', ', $allowedMethods));
347
348
        // append default parameters
349
        $oauth['oauth_consumer_key']     = $this->getConsumerKey();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$oauth was never initialized. Although not strictly required by PHP, it is generally a good practice to add $oauth = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
The method getConsumerKey() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
350
        $oauth['oauth_nonce']            = md5(microtime() . rand());
351
        $oauth['oauth_timestamp']        = time();
352
        $oauth['oauth_token']            = $this->getOAuthToken();
0 ignored issues
show
The method getOAuthToken() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
353
        $oauth['oauth_signature_method'] = 'HMAC-SHA1';
354
        $oauth['oauth_version']          = '1.0';
355
356
        // set data
357
        $data = $oauth;
358
        if (!empty($parameters)) $data = array_merge($data, $parameters);
359
360
        // calculate the base string
361
        $base = $this->calculateBaseString(self::API_URL . '/' . $url, $method, $data);
0 ignored issues
show
The method calculateBaseString() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
362
363
        // add sign into the parameters
364
        $oauth['oauth_signature'] = $this->hmacsha1($this->getConsumerSecret() . '&' . $this->getOAuthTokenSecret(), $base);
0 ignored issues
show
The method getConsumerSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method getOAuthTokenSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method hmacsha1() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
365
366
        $headers[] = $this->calculateHeader($oauth, self::API_URL . '/' . $url);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$headers was never initialized. Although not strictly required by PHP, it is generally a good practice to add $headers = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
The method calculateHeader() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
367
        $headers[] = 'Expect:';
368
369
        // based on the method, we should handle the parameters in a different way
370
        if ($method === 'POST') {
371
            // file provided?
372
            if ($filePath != null) {
373
                // build a boundary
374
                $boundary = md5(time());
375
376
                // process file
377
                $fileInfo = pathinfo($filePath);
378
379
                // set mimeType
380
                $mimeType = 'application/octet-stream';
381
                if ($fileInfo['extension'] === 'jpg' || $fileInfo['extension'] === 'jpeg') {
382
                    $mimeType = 'image/jpeg';
383
                } elseif ($fileInfo['extension'] === 'gif') $mimeType = 'image/gif';
384
                elseif ($fileInfo['extension'] === 'png') $mimeType = 'image/png';
385
386
                // init var
387
                $content = '--' . $boundary . "\r\n";
0 ignored issues
show
$content 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...
388
389
                // set file
390
                $content = 'Content-Disposition: form-data; name="image";filename="' . $fileInfo['basename'] . '"' . "\r\n" . 'Content-Type: ' . $mimeType . "\r\n\r\n" . file_get_contents($filePath) . "\r\n--" . $boundary . "\r\n";
391
392
                // build headers
393
                $headers[] = 'Content-Type: multipart/form-data; boundary=' . $boundary;
394
                $headers[] = 'Content-Length: ' . strlen($content);
395
396
                // set content
397
                $options[CURLOPT_POSTFIELDS] = $content;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
398
            } // no file
399
            else $options[CURLOPT_POSTFIELDS] = $this->buildQuery($parameters);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
The method buildQuery() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
400
401
            // enable post
402
            $options[CURLOPT_POST] = 1;
403
        } else {
404
            // add the parameters into the querystring
405
            if (!empty($parameters)) $url .= '?' . $this->buildQuery($parameters);
0 ignored issues
show
The method buildQuery() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
406
        }
407
408
        // set options
409
        $options[CURLOPT_URL]            = self::API_URL . '/' . $url;
0 ignored issues
show
The variable $options 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...
410
        $options[CURLOPT_PORT]           = self::API_PORT;
411
        $options[CURLOPT_USERAGENT]      = $this->getUserAgent();
0 ignored issues
show
The method getUserAgent() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
412
        $options[CURLOPT_FOLLOWLOCATION] = true;
413
        $options[CURLOPT_RETURNTRANSFER] = true;
414
        $options[CURLOPT_TIMEOUT]        = (int)$this->getTimeOut();
0 ignored issues
show
The method getTimeOut() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
415
        $options[CURLOPT_SSL_VERIFYPEER] = false;
416
        $options[CURLOPT_SSL_VERIFYHOST] = false;
417
        $options[CURLOPT_HTTP_VERSION]   = CURL_HTTP_VERSION_1_1;
418
        $options[CURLOPT_HTTPHEADER]     = $headers;
419
420
        // init
421
        if ($this->curl == null) $this->curl = curl_init();
422
423
        // set options
424
        curl_setopt_array($this->curl, $options);
425
426
        // execute
427
        $response = curl_exec($this->curl);
428
        $headers  = curl_getinfo($this->curl);
429
430
        // fetch errors
431
        $errorNumber  = curl_errno($this->curl);
0 ignored issues
show
$errorNumber 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...
432
        $errorMessage = curl_error($this->curl);
433
434
        // we don't expext JSON, return the response
435
        if (!$expectJSON) return $response;
436
437
        // replace ids with their string values, added because of some PHP-version can't handle these large values
438
        $response = preg_replace('/id":(\d+)/', 'id":"\1"', $response);
439
440
        // we expect JSON, so decode it
441
        $json = @json_decode($response, true);
442
443
        // validate JSON
444
        if ($json === null) {
445
            // should we provide debug information
446 View Code Duplication
            if (self::DEBUG) {
0 ignored issues
show
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...
447
                // make it output proper
448
                echo '<pre>';
449
450
                // dump the header-information
451
                var_dump($headers);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($headers); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
452
453
                // dump the error
454
                var_dump($errorMessage);
455
456
                // dump the raw response
457
                var_dump($response);
458
459
                // end proper format
460
                echo '</pre>';
461
            }
462
463
            // throw exception
464
            throw new TwitterException('Invalid response.');
465
        }
466
467
        // any errors
468
        if (isset($json['errors'])) {
469
            // should we provide debug information
470 View Code Duplication
            if (self::DEBUG) {
0 ignored issues
show
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...
471
                // make it output proper
472
                echo '<pre>';
473
474
                // dump the header-information
475
                var_dump($headers);
476
477
                // dump the error
478
                var_dump($errorMessage);
479
480
                // dump the raw response
481
                var_dump($response);
482
483
                // end proper format
484
                echo '</pre>';
485
            }
486
487
            // throw exception
488
            if (isset($json['errors'][0]['message'])) {
489
                throw new TwitterException($json['errors'][0]['message']);
490
            } else throw new TwitterException('Invalid response.');
491
        }
492
493
        // any error
494
        if (isset($json['error'])) {
495
            // should we provide debug information
496
            if (self::DEBUG) {
497
                // make it output proper
498
                echo '<pre>';
499
500
                // dump the header-information
501
                var_dump($headers);
502
503
                // dump the raw response
504
                var_dump($response);
505
506
                // end proper format
507
                echo '</pre>';
508
            }
509
510
            // throw exception
511
            throw new TwitterException($json['error']);
512
        }
513
514
        // return
515
        return $json;
516
    }
517
518
    /**
519
     * Get the consumer key
520
     *
521
     * @return    string
522
     */
523
    private function getConsumerKey()
524
    {
525
        return $this->consumerKey;
0 ignored issues
show
The property consumerKey does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
526
    }
527
528
    /**
529
     * Get the consumer secret
530
     *
531
     * @return    string
532
     */
533
    private function getConsumerSecret()
534
    {
535
        return $this->consumerSecret;
0 ignored issues
show
The property consumerSecret does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
536
    }
537
538
    /**
539
     * Get the oAuth-token
540
     *
541
     * @return    string
542
     */
543
    private function getOAuthToken()
544
    {
545
        return $this->oAuthToken;
0 ignored issues
show
The property oAuthToken does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
546
    }
547
548
    /**
549
     * Get the oAuth-token-secret
550
     *
551
     * @return    string
552
     */
553
    private function getOAuthTokenSecret()
554
    {
555
        return $this->oAuthTokenSecret;
0 ignored issues
show
The property oAuthTokenSecret does not seem to exist. Did you mean oAuthToken?

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...
556
    }
557
558
    /**
559
     * Get the timeout
560
     *
561
     * @return    int
562
     */
563
    public function getTimeOut()
564
    {
565
        return (int)$this->timeOut;
0 ignored issues
show
The property timeOut does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
566
    }
567
568
    /**
569
     * Get the useragent that will be used. Our version will be prepended to yours.
570
     * It will look like: "PHP Twitter/<version> <your-user-agent>"
571
     *
572
     * @return    string
573
     */
574
    public function getUserAgent()
575
    {
576
        return (string)'PHP Twitter/' . self::VERSION . ' ' . $this->userAgent;
0 ignored issues
show
The property userAgent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
577
    }
578
579
    /**
580
     * Set the consumer key
581
     *
582
     * @return    void
583
     * @param    string $key The consumer key to use.
584
     */
585
    private function setConsumerKey($key)
586
    {
587
        $this->consumerKey = (string)$key;
588
    }
589
590
    /**
591
     * Set the consumer secret
592
     *
593
     * @return    void
594
     * @param    string $secret The consumer secret to use.
595
     */
596
    private function setConsumerSecret($secret)
597
    {
598
        $this->consumerSecret = (string)$secret;
599
    }
600
601
    /**
602
     * Set the oAuth-token
603
     *
604
     * @return    void
605
     * @param    string $token The token to use.
606
     */
607
    public function setOAuthToken($token)
608
    {
609
        $this->oAuthToken = (string)$token;
610
    }
611
612
    /**
613
     * Set the oAuth-secret
614
     *
615
     * @return    void
616
     * @param    string $secret The secret to use.
617
     */
618
    public function setOAuthTokenSecret($secret)
619
    {
620
        $this->oAuthTokenSecret = (string)$secret;
0 ignored issues
show
The property oAuthTokenSecret does not seem to exist. Did you mean oAuthToken?

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...
621
    }
622
623
    /**
624
     * Set the timeout
625
     *
626
     * @return    void
627
     * @param    int $seconds The timeout in seconds
628
     */
629
    public function setTimeOut($seconds)
630
    {
631
        $this->timeOut = (int)$seconds;
632
    }
633
634
    /**
635
     * Get the useragent that will be used. Our version will be prepended to yours.
636
     * It will look like: "PHP Twitter/<version> <your-user-agent>"
637
     *
638
     * @return    void
639
     * @param    string $userAgent Your user-agent, it should look like <app-name>/<app-version>
640
     */
641
    public function setUserAgent($userAgent)
642
    {
643
        $this->userAgent = (string)$userAgent;
644
    }
645
646
    /**
647
     * Build the signature for the data
648
     *
649
     * @return    string
650
     * @param    string $key  The key to use for signing.
651
     * @param    string $data The data that has to be signed.
652
     */
653
    private function hmacsha1($key, $data)
654
    {
655
        return base64_encode(hash_hmac('SHA1', $data, $key, true));
656
    }
657
658
    /**
659
     * URL-encode method for internatl use
660
     *
661
     * @return    string
662
     * @param    mixed $value The value to encode.
663
     */
664
    private static function urlencode_rfc3986($value)
665
    {
666
        if (is_array($value)) {
667
            return array_map(array('Twitter', 'urlencode_rfc3986'), $value);
668
        } else {
669
            $search  = array('+', ' ', '%7E', '%');
670
            $replace = array('%20', '%20', '~', '%25');
671
672
            return str_replace($search, $replace, urlencode($value));
673
        }
674
    }
675
676
677
    // Timeline resources
678
    /**
679
     * Returns the 20 most recent statuses from non-protected users who have set a custom user icon.
680
     * The public timeline is cached for 60 seconds and requesting it more often than that is unproductive and a waste of resources.
681
     *
682
     * @return    array
683
     * @param    bool [optional] $skipUser    When true each tweet returned in a timeline will not contain an entire user object. Instead, the user node will contain only an id element to indicate the numerical ID of the Twitter user that set the status.
684
     */
685
    public function statusesPublicTimeline($skipUser = false)
686
    {
687
        // redefine
688
        $skipUser = (bool)$skipUser;
689
690
        // build parameters
691
        $parameters = array();
692
        if ($skipUser) $parameters['skip_user'] = 'true';
693
694
        // make the call
695
        return (array)$this->doCall('statuses/public_timeline.json', $parameters);
696
    }
697
698
    /**
699
     * Returns the 20 most recent statuses posted by the authenticating user and that user's friends. This is the equivalent of /timeline/home on the Web.
700
     *
701
     * @return    array
702
     * @param    string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
703
     * @param    string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
704
     * @param    int    [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
705
     * @param    int    [optional] $page            Specifies the page of results to retrieve.
706
     * @param    bool   [optional] $skipUser    When true each tweet returned in a timeline will not contain an entire user object. Instead, the user node will contain only an id element to indicate the numerical ID of the Twitter user that set the status.
707
     */
708 View Code Duplication
    public function statusesHomeTimeline($sinceId = null, $maxId = null, $count = null, $page = null, $skipUser = false)
0 ignored issues
show
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...
709
    {
710
        // redefine
711
        $skipUser = (bool)$skipUser;
712
713
        // build parameters
714
        $parameters = array();
715
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
716
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
717
        if ($count != null) $parameters['count'] = (int)$count;
718
        if ($page != null) $parameters['page'] = (int)$page;
719
        if ($skipUser) $parameters['skip_user'] = 'true';
720
721
        // make the call
722
        return (array)$this->doCall('statuses/home_timeline.json', $parameters, true);
723
    }
724
725
    /**
726
     * Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.
727
     * This is the equivalent of /timeline/home on the Web.
728
     *
729
     * Usage note: This home_timeline call is identical to statuses/friends_timeline, except that home_timeline also contains retweets, while statuses/friends_timeline does not for backwards compatibility reasons.
730
     * In a future version of the API, statuses/friends_timeline will be deprected and replaced by home_timeline.
731
     *
732
     * @return    array
733
     * @param    string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
734
     * @param    string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
735
     * @param    int    [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
736
     * @param    int    [optional] $page            Specifies the page of results to retrieve.
737
     * @param    bool   [optional] $skipUser    When true each tweet returned in a timeline will not contain an entire user object. Instead, the user node will contain only an id element to indicate the numerical ID of the Twitter user that set the status.
738
     */
739 View Code Duplication
    public function statusesFriendsTimeline($sinceId = null, $maxId = null, $count = null, $page = null, $skipUser = false)
0 ignored issues
show
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...
740
    {
741
        // redefine
742
        $skipUser = (bool)$skipUser;
743
744
        // build parameters
745
        $parameters = array();
746
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
747
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
748
        if ($count != null) $parameters['count'] = (int)$count;
749
        if ($page != null) $parameters['page'] = (int)$page;
750
        if ($skipUser) $parameters['skip_user'] = 'true';
751
752
        // make the call
753
        return (array)$this->doCall('statuses/friends_timeline.json', $parameters, true);
754
    }
755
756
    /**
757
     * Returns the 20 most recent statuses posted from the authenticating user. It's also possible to request another user's timeline via the id parameter.
758
     * This is the equivalent of the Web / page for your own user, or the profile page for a third party.
759
     *
760
     * For backwards compatibility reasons, retweets are stripped out of the user_timeline when calling in XML or JSON (they appear with 'RT' in RSS and Atom).
761
     * If you'd like them included, you can merge them in from statuses retweeted_by_me.
762
     *
763
     * @return    array
764
     * @param    string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
765
     * @param    string [optional] $userId        Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
766
     * @param    string [optional] $screenName    Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
767
     * @param    string [optional] $sinceId        Returns results with an ID greater than (that is, more recent than) the specified ID.
768
     * @param    string [optional] $maxId            Returns results with an ID less than (that is, older than) or equal to the specified ID.
769
     * @param    int    [optional] $count            Specifies the number of records to retrieve. May not be greater than 200.
770
     * @param    int    [optional] $page                Specifies the page of results to retrieve.
771
     * @param    bool   [optional] $skipUser        When true each tweet returned in a timeline will not contain an entire user object. Instead, the user node will contain only an id element to indicate the numerical ID of the Twitter user that set the status.
772
     */
773
    public function statusesUserTimeline($id = null, $userId = null, $screenName = null, $sinceId = null, $maxId = null, $count = null, $page = null, $skipUser = false)
774
    {
775
        // redefine
776
        $skipUser = (bool)$skipUser;
777
778
        // build parameters
779
        $parameters = array();
780
        if ($id != null) $parameters['id'] = (string)$id;
781
        if ($userId != null) $parameters['user_id'] = (string)$userId;
782
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
783
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
784
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
785
        if ($count != null) $parameters['count'] = (int)$count;
786
        if ($page != null) $parameters['page'] = (int)$page;
787
        if ($skipUser) $parameters['skip_user'] = 'true';
788
789
        // make the call
790
        return (array)$this->doCall('statuses/user_timeline.json', $parameters, true);
791
    }
792
793
    /**
794
     * Returns the 20 most recent mentions (status containing @username) for the authenticating user.
795
     *
796
     *
797
     * @param null $sinceId
798
     * @param null $maxId
799
     * @param null $count
800
     * @param null $page
801
     * @return array
802
     * @throws TwitterException
803
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
804
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
805
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
806
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
807
     */
808 View Code Duplication
    public function statusesMentions($sinceId = null, $maxId = null, $count = null, $page = null)
0 ignored issues
show
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...
809
    {
810
        // validate
811
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
812
813
        // build parameters
814
        $parameters = array();
815
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
816
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
817
        if ($count != null) $parameters['count'] = (int)$count;
818
        if ($page != null) $parameters['page'] = (int)$page;
819
820
        // make the call
821
        return (array)$this->doCall('statuses/mentions.json', $parameters);
822
    }
823
824
    /**
825
     * Returns the 20 most recent retweets posted by the authenticating user.
826
     *
827
     *
828
     * @param null $sinceId
829
     * @param null $maxId
830
     * @param null $count
831
     * @param null $page
832
     * @return array
833
     * @throws TwitterException
834
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
835
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
836
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
837
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
838
     */
839 View Code Duplication
    public function statusesRetweetedByMe($sinceId = null, $maxId = null, $count = null, $page = null)
0 ignored issues
show
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...
840
    {
841
        // validate
842
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
843
844
        // build parameters
845
        $parameters = array();
846
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
847
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
848
        if ($count != null) $parameters['count'] = (int)$count;
849
        if ($page != null) $parameters['page'] = (int)$page;
850
851
        // make the call
852
        return (array)$this->doCall('statuses/retweeted_by_me.json', $parameters);
853
    }
854
855
    /**
856
     * Returns the 20 most recent retweets posted by the authenticating user's friends.
857
     *
858
     *
859
     * @param null $sinceId
860
     * @param null $maxId
861
     * @param null $count
862
     * @param null $page
863
     * @return array
864
     * @throws TwitterException
865
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
866
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
867
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
868
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
869
     */
870 View Code Duplication
    public function statusesRetweetedToMe($sinceId = null, $maxId = null, $count = null, $page = null)
0 ignored issues
show
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...
871
    {
872
        // validate
873
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
874
875
        // build parameters
876
        $parameters = array();
877
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
878
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
879
        if ($count != null) $parameters['count'] = (int)$count;
880
        if ($page != null) $parameters['page'] = (int)$page;
881
882
        // make the call
883
        return (array)$this->doCall('statuses/retweeted_by_me.json', $parameters);
884
    }
885
886
887
    // Tweets resources
888
    /**
889
     * Returns the 20 most recent tweets of the authenticated user that have been retweeted by others.
890
     *
891
     *
892
     * @param null $sinceId
893
     * @param null $maxId
894
     * @param null $count
895
     * @param null $page
896
     * @return array
897
     * @throws TwitterException
898
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
899
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
900
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
901
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
902
     */
903 View Code Duplication
    public function statusesReweetsOfMe($sinceId = null, $maxId = null, $count = null, $page = null)
0 ignored issues
show
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...
904
    {
905
        // validate
906
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
907
908
        // build parameters
909
        $parameters = array();
910
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
911
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
912
        if ($count != null) $parameters['count'] = (int)$count;
913
        if ($page != null) $parameters['page'] = (int)$page;
914
915
        // make the call
916
        return (array)$this->doCall('statuses/retweets_of_me.json', $parameters);
917
    }
918
919
    /**
920
     * Returns a single status, specified by the id parameter below. The status's author will be returned inline.
921
     *
922
     * @return    array
923
     * @param    string $id The numerical ID of the desired status.
924
     */
925
    public function statusesShow($id)
926
    {
927
        // build parameters
928
        $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
929
930
        // make the call
931
        return (array)$this->doCall('statuses/show.json', $parameters);
932
    }
933
934
    /**
935
     * Updates the authenticating user's status. A status update with text identical to the authenticating user's text identical to the authenticating user's current status will be ignored to prevent duplicates.
936
     *
937
     * @return    array
938
     * @param    string $status The text of your status update, up to 140 characters. URL encode as necessary.
939
     * @param           string  [optional] $inReplyToStatusId        The ID of an existing status that the update is in reply to.
940
     * @param           float   [optional] $lat                    The location's latitude that this tweet refers to.
941
     * @param           float   [optional] $long                    The location's longitude that this tweet refers to.
942
     * @param           string  [optional] $placeId                A place in the world. These IDs can be retrieved from geo/reverse_geocode.
943
     * @param           bool    [optional] $displayCoordinates        Whether or not to put a pin on the exact coordinates a tweet has been sent from.
944
     */
945
    public function statusesUpdate($status, $inReplyToStatusId = null, $lat = null, $long = null, $placeId = null, $displayCoordinates = false)
946
    {
947
        // build parameters
948
        $parameters['status'] = (string)$status;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
949
        if ($inReplyToStatusId != null) $parameters['in_reply_to_status_id'] = (string)$inReplyToStatusId;
950
        if ($lat != null) $parameters['lat'] = (float)$lat;
951
        if ($long != null) $parameters['long'] = (float)$long;
952
        if ($placeId != null) $parameters['place_id'] = (string)$placeId;
953
        if ($displayCoordinates) $parameters['display_coordinates'] = 'true';
954
955
        // make the call
956
        return (array)$this->doCall('statuses/update.json', $parameters, true, 'POST');
957
    }
958
959
    /**
960
     * Destroys the status specified by the required ID parameter.
961
     * Usage note: The authenticating user must be the author of the specified status.
962
     *
963
     * @return    bool
964
     * @param    string $id The numerical ID of the desired status.
965
     */
966
    public function statusesDestroy($id)
967
    {
968
        // build parameters
969
        $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
970
971
        // make the call
972
        return (array)$this->doCall('statuses/destroy.json', $parameters, true, 'POST');
973
    }
974
975
    /**
976
     * Retweets a tweet. Returns the original tweet with retweet details embedded.
977
     *
978
     * @return    array
979
     * @param    string $id The numerical ID of the desired status.
980
     */
981
    public function statusesRetweet($id)
982
    {
983
        // make the call
984
        return (array)$this->doCall('statuses/retweet/' . $id . '.json', null, true, 'POST');
985
    }
986
987
    /**
988
     * Returns up to 100 of the first retweets of a given tweet.
989
     *
990
     *
991
     * @param    string $id The numerical ID of the desired status.
992
     * @param           int [optional] $count    Specifies the number of records to retrieve. May not be greater than 100.
993
     * @return array
994
     * @throws TwitterException
995
     */
996
    public function statusesRetweets($id, $count = null)
997
    {
998
        // validate
999
        if ($count != null && $count > 100) throw new TwitterException('Count may not be greater than 100.');
1000
1001
        // build parameters
1002
        $parameters = null;
1003
        if ($count != null) $parameters['count'] = (int)$count;
1004
1005
        // make the call
1006
        return (array)$this->doCall('statuses/retweets/' . $id . '.json', $parameters);
1007
    }
1008
1009
    /**
1010
     * Show user objects of up to 100 members who retweeted the status.
1011
     *
1012
     *
1013
     * @param    string $id The numerical ID of the desired status.
1014
     * @param null      $count
1015
     * @param null      $page
1016
     * @return array
1017
     * @throws TwitterException
1018
     * @internal param $int [optional] $count    Specifies the number of records to retrieve. May not be greater than 200.
1019
     * @internal param $int [optional] $page        Specifies the page of results to retrieve.
1020
     */
1021 View Code Duplication
    public function statusesIdRetweetedBy($id, $count = null, $page = null)
0 ignored issues
show
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...
1022
    {
1023
        // validate
1024
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
1025
1026
        // build parameters
1027
        $parameters = null;
1028
        if ($count != null) $parameters['count'] = (int)$count;
1029
        if ($page != null) $parameters['page'] = (int)$page;
1030
1031
        // make the call
1032
        return (array)$this->doCall('statuses/' . (string)$id . '/retweeted_by.json', $parameters, true);
1033
    }
1034
1035
    /**
1036
     * Show user ids of up to 100 users who retweeted the status.
1037
     *
1038
     *
1039
     * @param    string $id The numerical ID of the desired status.
1040
     * @param null      $count
1041
     * @param null      $page
1042
     * @return array
1043
     * @throws TwitterException
1044
     * @internal param $int [optional] $count    Specifies the number of records to retrieve. May not be greater than 200.
1045
     * @internal param $int [optional] $page        Specifies the page of results to retrieve.
1046
     */
1047 View Code Duplication
    public function statusesIdRetweetedByIds($id, $count = null, $page = null)
0 ignored issues
show
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...
1048
    {
1049
        // validate
1050
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
1051
1052
        // build parameters
1053
        $parameters = null;
1054
        if ($count != null) $parameters['count'] = (int)$count;
1055
        if ($page != null) $parameters['page'] = (int)$page;
1056
1057
        // make the call
1058
        return (array)$this->doCall('statuses/' . (string)$id . '/retweeted_by/ids.json', $parameters, true);
1059
    }
1060
1061
1062
    // User resources
1063
    /**
1064
     * Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
1065
     * The author's most recent status will be returned inline.
1066
     *
1067
     *
1068
     * @param null $id
1069
     * @param null $userId
1070
     * @param null $screenName
1071
     * @return array
1072
     * @throws TwitterException
1073
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1074
     * @internal param $string [optional] $userId        Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1075
     * @internal param $string [optional] $screenName    Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1076
     */
1077
    public function usersShow($id = null, $userId = null, $screenName = null)
1078
    {
1079
        // validate
1080
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
1081
1082
        // build parameters
1083
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1084
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
1085
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1086
1087
        // make the call
1088
        return (array)$this->doCall('users/show.json', $parameters);
1089
    }
1090
1091
    /**
1092
     * Return up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two.
1093
     * The author's most recent status (if the authenticating user has permission) will be returned inline.
1094
     *
1095
     *
1096
     * @param null $userIds
1097
     * @param null $screenNames
1098
     * @return array
1099
     * @throws TwitterException
1100
     * @internal param $mixed [optional] $userIds        A comma separated list of user IDs, up to 100 in total.
1101
     * @internal param $mixed [optional] $screenNames    A comma separated list of screen names, up to 100 in total.
1102
     */
1103
    public function usersLookup($userIds = null, $screenNames = null)
1104
    {
1105
        // redefine
1106
        $userIds     = (array)$userIds;
1107
        $screenNames = (array)$screenNames;
1108
1109
        // validate
1110
        if (empty($userIds) && empty($screenNames)) throw new TwitterException('Specify an userId or a screenName.');
1111
1112
        // build parameters
1113
        if (!empty($userIds)) $parameters['user_id'] = implode(',', $userIds);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1114
        if (!empty($screenNames)) $parameters['screen_name'] = implode(',', $screenNames);
0 ignored issues
show
The variable $parameters 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...
1115
1116
        // make the call
1117
        return (array)$this->doCall('users/lookup.json', $parameters, true);
1118
1119
    }
1120
1121
    /**
1122
     * Run a search for users similar to the Find People button on Twitter.com; the same results returned by people search on Twitter.com will be returned by using this API.
1123
     * Usage note: It is only possible to retrieve the first 1000 matches from this API.
1124
     *
1125
     * @return    array
1126
     * @param    string $q  The search query term.
1127
     * @param           int [optional] $perPage    Specifies the number of results to retrieve.
1128
     * @param           int [optional] $page        Specifies the page of results to retrieve.
1129
     */
1130
    public function usersSearch($q, $perPage = null, $page = null)
1131
    {
1132
        // build parameters
1133
        $parameters['q'] = (string)$q;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1134
        if ($perPage != null) $parameters['per_page'] = (int)$perPage;
1135
        if ($page != null) $parameters['page'] = (int)$page;
1136
1137
        // make the call
1138
        return (array)$this->doCall('users/search.json', $parameters, true);
1139
1140
    }
1141
1142
    /**
1143
     * Access to Twitter's suggested user list. This returns the list of suggested user categories. The category can be used in the users/suggestions/category  endpoint to get the users in that category.
1144
     *
1145
     * @return    array
1146
     */
1147
    public function usersSuggestions()
1148
    {
1149
        return (array)$this->doCall('users/suggestions.json', null, true);
1150
    }
1151
1152
    /**
1153
     * Access the users in a given category of the Twitter suggested user list.
1154
     * It is recommended that end clients cache this data for no more than one hour.
1155
     *
1156
     * @return    array
1157
     * @param    string $slug The short name of list or a category.
1158
     */
1159
    public function usersSuggestionsSlug($slug)
1160
    {
1161
        return (array)$this->doCall('users/suggestions/' . (string)$slug . '.json');
1162
    }
1163
1164
    /**
1165
     * Returns a user's friends, each with current status inline. They are ordered by the order in which the user followed them, most recently followed first, 100 at a time.
1166
     * (Please note that the result set isn't guaranteed to be 100 every time as suspended users will be filtered out.)
1167
     *
1168
     * Use the cursor option to access older friends.
1169
     * With no user specified, request defaults to the authenticated user's friends.
1170
     * It's also possible to request another user's friends list via the id, screen_name or user_id parameter.
1171
     *
1172
     * @return    array
1173
     * @param    string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1174
     * @param    string [optional] $userId        Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1175
     * @param    string [optional] $screenName    Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1176
     * @param    int    [optional] $cursor            Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1177
     */
1178 View Code Duplication
    public function statusesFriends($id = null, $userId = null, $screenName = null, $cursor = null)
0 ignored issues
show
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...
1179
    {
1180
        // build parameters
1181
        $parameters = array();
1182
        if ($id != null) $parameters['id'] = (string)$id;
1183
        if ($userId != null) $parameters['user_id'] = (string)$userId;
1184
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1185
        if ($cursor != null) $parameters['cursor'] = (int)$cursor;
1186
1187
        // make the call
1188
        return (array)$this->doCall('statuses/friends.json', $parameters);
1189
    }
1190
1191
    /**
1192
     * Returns the authenticating user's followers, each with current status inline. They are ordered by the order in which they followed the user, 100 at a time. (Please note that the result set isn't guaranteed to be 100 every time as suspended users will be filtered out.)
1193
     * Use the cursor parameter to access earlier followers.
1194
     *
1195
     * @return    array
1196
     * @param    string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1197
     * @param    string [optional] $userId        Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1198
     * @param    string [optional] $screenName    Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1199
     * @param    int    [optional] $cursor            Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1200
     */
1201 View Code Duplication
    public function statusesFollowers($id = null, $userId = null, $screenName = null, $cursor = null)
0 ignored issues
show
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...
1202
    {
1203
        // build parameters
1204
        $parameters = array();
1205
        if ($id != null) $parameters['id'] = (string)$id;
1206
        if ($userId != null) $parameters['user_id'] = (string)$userId;
1207
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1208
        if ($cursor != null) $parameters['cursor'] = (int)$cursor;
1209
1210
        // make the call
1211
        return (array)$this->doCall('statuses/followers.json', $parameters);
1212
    }
1213
1214
1215
    // Trends resources
1216
    /**
1217
     * Returns the top ten topics that are currently trending on Twitter.
1218
     * The response includes the time of the request, the name of each trend, and the url to the Twitter Search results page for that topic.
1219
     *
1220
     * @return    array
1221
     */
1222
    public function trends()
1223
    {
1224
        return (array)$this->doCall('trends.json');
1225
    }
1226
1227
    /**
1228
     * Returns the current top 10 trending topics on Twitter.
1229
     * The response includes the time of the request, the name of each trending topic, and query used on Twitter Search results page for that topic.
1230
     *
1231
     * @return    array
1232
     * @param    string [optional] $exclude    Setting this equal to hashtags will remove all hashtags from the trends list.
1233
     */
1234
    public function trendsCurrent($exclude = null)
1235
    {
1236
        // build parameters
1237
        $parameters = array();
1238
        if ($exclude != null) $parameters['exclude'] = (string)$exclude;
1239
1240
        // make the call
1241
        return (array)$this->doCall('trends/current.json', $parameters);
1242
    }
1243
1244
    /**
1245
     * Returns the top 20 trending topics for each hour in a given day.
1246
     *
1247
     * @return    array
1248
     * @param    string [optional] $exclude    Setting this equal to hashtags will remove all hashtags from the trends list.
1249
     * @param    string [optional] $date        Permits specifying a start date for the report. The date should be formatted YYYY-MM-DD.
1250
     */
1251 View Code Duplication
    public function trendsDaily($exclude = null, $date = null)
0 ignored issues
show
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...
1252
    {
1253
        // build parameters
1254
        $parameters = array();
1255
        if ($exclude != null) $parameters['exclude'] = (string)$exclude;
1256
        if ($date != null) $parameters['date'] = (string)$date;
1257
1258
        // make the call
1259
        return (array)$this->doCall('trends/daily.json', $parameters);
1260
    }
1261
1262
    /**
1263
     * Returns the top 30 trending topics for each day in a given week.
1264
     *
1265
     * @return    array
1266
     * @param    string [optional] $exclude    Setting this equal to hashtags will remove all hashtags from the trends list.
1267
     * @param    string [optional] $date        Permits specifying a start date for the report. The date should be formatted YYYY-MM-DD.
1268
     */
1269 View Code Duplication
    public function trendsWeekly($exclude = null, $date = null)
0 ignored issues
show
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...
1270
    {
1271
        // build parameters
1272
        $parameters = array();
1273
        if ($exclude != null) $parameters['exclude'] = (string)$exclude;
1274
        if ($date != null) $parameters['date'] = (string)$date;
1275
1276
        // make the call
1277
        return (array)$this->doCall('trends/weekly.json', $parameters);
1278
    }
1279
1280
1281
    // List resources
1282
    /**
1283
     * Creates a new list for the authenticated user. Accounts are limited to 20 lists.
1284
     *
1285
     *
1286
     * @param    string $user The user.
1287
     * @param    string $name The name of the list you are creating.
1288
     * @param null      $mode
1289
     * @param null      $description
1290
     * @return array
1291
     * @throws TwitterException
1292
     * @internal param $string [optional] $mode            Whether your list is public or private. Values can be public or private. Lists are public by default if no mode is specified.
1293
     * @internal param $string [optional] $description    The description of the list you are creating.
1294
     */
1295
    public function userListsCreate($user, $name, $mode = null, $description = null)
1296
    {
1297
        // possible modes
1298
        $allowedModes = array('public', 'private');
1299
1300
        // validate
1301 View Code Duplication
        if ($mode != null && !in_array($mode, $allowedModes)) throw new TwitterException('Invalid mode (), possible values are: ' . implode($allowedModes) . '.');
0 ignored issues
show
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...
1302
1303
        // build parameters
1304
        $parameters['name'] = (string)$name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1305
        if ($mode != null) $parameters['mode'] = (string)$mode;
1306
        if ($description != null) $parameters['description'] = (string)$description;
1307
1308
        // make the call
1309
        return (array)$this->doCall((string)$user . '/lists.json', $parameters, true, 'POST');
1310
    }
1311
1312
    /**
1313
     * List the lists of the specified user. Private lists will be included if the authenticated users is the same as the user who's lists are being returned.
1314
     *
1315
     * @return    array
1316
     * @param    string $user  The user.
1317
     * @param           string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1318
     */
1319
    public function userLists($user, $cursor = null)
1320
    {
1321
        $parameters = null;
1322
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1323
1324
        // make the call
1325
        return (array)$this->doCall((string)$user . '/lists.json', $parameters, true);
1326
    }
1327
1328
    /**
1329
     * Show the specified list. Private lists will only be shown if the authenticated user owns the specified list.
1330
     *
1331
     * @return    array
1332
     * @param    string $user The user.
1333
     * @param    string $id   The id of the list.
1334
     */
1335
    public function userListsId($user, $id)
1336
    {
1337
        // make the call
1338
        return (array)$this->doCall((string)$user . '/lists/' . (string)$id . '.json', null, true);
1339
    }
1340
1341
    /**
1342
     * Updates the specified list.
1343
     *
1344
     *
1345
     * @param    string $user The user.
1346
     * @param    string $id   The id of the list.
1347
     * @param null      $name
1348
     * @param null      $mode
1349
     * @param null      $description
1350
     * @return array
1351
     * @throws TwitterException
1352
     * @internal param $string [optional] $name            The name of the list you are creating.
1353
     * @internal param $string [optional] $mode            Whether your list is public or private. Values can be public or private. Lists are public by default if no mode is specified.
1354
     * @internal param $string [optional] $description    The description of the list you are creating.
1355
     */
1356
    public function userListsIdUpdate($user, $id, $name = null, $mode = null, $description = null)
1357
    {
1358
        // possible modes
1359
        $allowedModes = array('public', 'private');
1360
1361
        // validate
1362 View Code Duplication
        if ($mode != null && !in_array($mode, $allowedModes)) throw new TwitterException('Invalid mode (), possible values are: ' . implode($allowedModes) . '.');
0 ignored issues
show
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...
1363
1364
        // build parameters
1365
        if ($name != null) $parameters['name'] = (string)$name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1366
        if ($mode != null) $parameters['mode'] = (string)$mode;
0 ignored issues
show
The variable $parameters 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...
1367
        if ($description != null) $parameters['description'] = (string)$description;
1368
1369
        // make the call
1370
        return (array)$this->doCall((string)$user . '/lists/' . (string)$id . '.json', $parameters, true, 'POST');
1371
    }
1372
1373
    /**
1374
     * Show tweet timeline for members of the specified list.
1375
     *
1376
     *
1377
     * @param    string $user The user.
1378
     * @param    string $id   The id of the list.
1379
     * @param null      $sinceId
1380
     * @param null      $maxId
1381
     * @param null      $count
1382
     * @param null      $page
1383
     * @return array
1384
     * @throws TwitterException
1385
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
1386
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
1387
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
1388
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
1389
     */
1390
    public function userListsIdStatuses($user, $id, $sinceId = null, $maxId = null, $count = null, $page = null)
1391
    {
1392
        // validate
1393
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
1394
1395
        // build parameters
1396
        $parameters = array();
1397
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
1398
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
1399
        if ($count != null) $parameters['per_page'] = (int)$count;
1400
        if ($page != null) $parameters['page'] = (int)$page;
1401
1402
        // make the call
1403
        return (array)$this->doCall((string)$user . '/lists/' . (string)$id . '/statuses.json', $parameters);
1404
    }
1405
1406
    /**
1407
     * List the lists the specified user has been added to.
1408
     *
1409
     * @return    array
1410
     * @param    string $user  The user.
1411
     * @param           string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1412
     */
1413
    public function userListsMemberships($user, $cursor = null)
1414
    {
1415
        $parameters = null;
1416
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1417
1418
        // make the call
1419
        return (array)$this->doCall((string)$user . '/lists/memberships.json', $parameters, true);
1420
    }
1421
1422
    /**
1423
     * List the lists the specified user follows.
1424
     *
1425
     * @return    array
1426
     * @param    string $user  The user.
1427
     * @param           string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1428
     */
1429
    public function userListsSubscriptions($user, $cursor = null)
1430
    {
1431
        $parameters = null;
1432
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1433
1434
        // make the call
1435
        return (array)$this->doCall((string)$user . '/lists/subscriptions.json', $parameters, true);
1436
    }
1437
1438
1439
    // List Members resources
1440
    /**
1441
     * Returns the members of the specified list.
1442
     *
1443
     * @return    array
1444
     * @param    string $user  The user.
1445
     * @param    string $id    The id of the list.
1446
     * @param           string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1447
     */
1448 View Code Duplication
    public function userListMembers($user, $id, $cursor = null)
0 ignored issues
show
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...
1449
    {
1450
        $parameters = null;
1451
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1452
1453
        // make the call
1454
        return (array)$this->doCall((string)$user . '/' . (string)$id . '/members.json', $parameters, true);
1455
    }
1456
1457
    /**
1458
     * Add a member to a list. The authenticated user must own the list to be able to add members to it. Lists are limited to having 500 members.
1459
     *
1460
     * @return    array
1461
     * @param    string $user   The user.
1462
     * @param    string $id     The id of the list.
1463
     * @param    string $userId The id or screen name of the user to add as a member of the list.
1464
     */
1465 View Code Duplication
    public function userListMembersCreate($user, $id, $userId)
0 ignored issues
show
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...
1466
    {
1467
        // build parameters
1468
        $parameters['id'] = (string)$userId;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1469
1470
        // make the call
1471
        return (array)$this->doCall((string)$user . '/' . (string)$id . '/members.json', $parameters, true, 'POST');
1472
    }
1473
1474
    /**
1475
     * Removes the specified member from the list. The authenticated user must be the list's owner to remove members from the list.
1476
     *
1477
     * @return    mixed
1478
     * @param    string $user   The user.
1479
     * @param    string $id     The id of the list.
1480
     * @param    string $userId Specfies the ID of the user for whom to return results for.
1481
     */
1482 View Code Duplication
    public function userListMembersDelete($user, $id, $userId)
0 ignored issues
show
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...
1483
    {
1484
        // build parameters
1485
        $parameters['id']      = (string)$userId;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1486
        $parameters['_method'] = 'DELETE';
1487
1488
        // make the call
1489
        return (array)$this->doCall((string)$user . '/' . (string)$id . '/members.json', $parameters, true, 'POST');
1490
    }
1491
1492
    /**
1493
     * Check if a user is a member of the specified list.
1494
     *
1495
     *
1496
     * @param    string $user   The user.
1497
     * @param    string $id     The id of the list.
1498
     * @param    string $userId Specfies the ID of the user for whom to return results for.
1499
     * @return mixed
1500
     * @throws TwitterException
1501
     */
1502 View Code Duplication
    public function userListMembersId($user, $id, $userId)
0 ignored issues
show
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...
1503
    {
1504
        try {
1505
            // make the call
1506
            return (array)$this->doCall((string)$user . '/' . (string)$id . '/members/' . (string)$userId . '.json', null, true);
1507
        } // catch exceptions
1508
        catch (TwitterException $e) {
1509
            if ($e->getMessage() === 'The specified user is not a member of this list') {
1510
                return false;
1511
            } else throw $e;
1512
        }
1513
    }
1514
1515
1516
    // List Subscribers resources
1517
    /**
1518
     * Returns the subscribers of the specified list.
1519
     *
1520
     * @return    array
1521
     * @param    string $user  The user.
1522
     * @param    string $id    The id of the list.
1523
     * @param           string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1524
     */
1525 View Code Duplication
    public function userListSubscribers($user, $id, $cursor = null)
0 ignored issues
show
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...
1526
    {
1527
        $parameters = null;
1528
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1529
1530
        // make the call
1531
        return (array)$this->doCall((string)$user . '/' . (string)$id . '/subscribers.json', $parameters, true);
1532
    }
1533
1534
    /**
1535
     * Make the authenticated user follow the specified list.
1536
     *
1537
     * @return    array
1538
     * @param    string $user The user.
1539
     * @param    string $id   The id of the list.
1540
     */
1541
    public function userListSubscribersCreate($user, $id)
1542
    {
1543
        // make the call
1544
        return (array)$this->doCall((string)$user . '/' . (string)$id . '/subscribers.json', null, true, 'POST');
1545
    }
1546
1547
    /**
1548
     * Unsubscribes the authenticated user form the specified list.
1549
     *
1550
     * @return    array
1551
     * @param    string $user The user.
1552
     * @param    string $id   The id of the list.
1553
     */
1554 View Code Duplication
    public function userListSubscribersDelete($user, $id)
0 ignored issues
show
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...
1555
    {
1556
        // build parameters
1557
        $parameters['_method'] = 'DELETE';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1558
1559
        // make the call
1560
        return (array)$this->doCall((string)$user . '/' . (string)$id . '/subscribers.json', $parameters, true, 'POST');
1561
    }
1562
1563
    /**
1564
     * Check if the specified user is a subscriber of the specified list.
1565
     *
1566
     *
1567
     * @param    string $user   The user.
1568
     * @param    string $id     The id of the list.
1569
     * @param    string $userId Specfies the ID of the user for whom to return results for.
1570
     * @return mixed
1571
     * @throws TwitterException
1572
     */
1573 View Code Duplication
    public function userListSubscribersId($user, $id, $userId)
0 ignored issues
show
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...
1574
    {
1575
        try {
1576
            // make the call
1577
            return (array)$this->doCall((string)$user . '/' . (string)$id . '/subscribers/' . (string)$userId . '.json', null, true);
1578
        } // catch exceptions
1579
        catch (TwitterException $e) {
1580
            if ($e->getMessage() === 'The specified user is not a subscriber of this list') {
1581
                return false;
1582
            } else throw $e;
1583
        }
1584
1585
    }
1586
1587
1588
    // Direct Messages resources
1589
    /**
1590
     * Returns a list of the 20 most recent direct messages sent to the authenticating user.
1591
     *
1592
     *
1593
     * @param null $sinceId
1594
     * @param null $maxId
1595
     * @param null $count
1596
     * @param null $page
1597
     * @return array
1598
     * @throws TwitterException
1599
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
1600
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
1601
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
1602
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
1603
     */
1604 View Code Duplication
    public function directMessages($sinceId = null, $maxId = null, $count = null, $page = null)
0 ignored issues
show
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...
1605
    {
1606
        // validate
1607
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
1608
1609
        // build parameters
1610
        $parameters = array();
1611
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
1612
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
1613
        if ($count != null) $parameters['count'] = (int)$count;
1614
        if ($page != null) $parameters['page'] = (int)$page;
1615
1616
        // make the call
1617
        return (array)$this->doCall('direct_messages.json', $parameters, true);
1618
    }
1619
1620
    /**
1621
     * Returns a list of the 20 most recent direct messages sent by the authenticating user.
1622
     *
1623
     *
1624
     * @param null $sinceId
1625
     * @param null $maxId
1626
     * @param null $count
1627
     * @param null $page
1628
     * @return array
1629
     * @throws TwitterException
1630
     * @internal param $string [optional] $sinceId    Returns results with an ID greater than (that is, more recent than) the specified ID.
1631
     * @internal param $string [optional] $maxId        Returns results with an ID less than (that is, older than) or equal to the specified ID.
1632
     * @internal param $int [optional] $count        Specifies the number of records to retrieve. May not be greater than 200.
1633
     * @internal param $int [optional] $page            Specifies the page of results to retrieve.
1634
     */
1635 View Code Duplication
    public function directMessagesSent($sinceId = null, $maxId = null, $count = null, $page = null)
0 ignored issues
show
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...
1636
    {
1637
        // validate
1638
        if ($count != null && $count > 200) throw new TwitterException('Count may not be greater than 200.');
1639
1640
        // build parameters
1641
        $parameters = array();
1642
        if ($sinceId != null) $parameters['since_id'] = (string)$sinceId;
1643
        if ($maxId != null) $parameters['max_id'] = (string)$maxId;
1644
        if ($count != null) $parameters['count'] = (int)$count;
1645
        if ($page != null) $parameters['page'] = (int)$page;
1646
1647
        // make the call
1648
        return (array)$this->doCall('direct_messages/sent.json', $parameters, true);
1649
    }
1650
1651
    /**
1652
     * Sends a new direct message to the specified user from the authenticating user.
1653
     * Requires both the user and text parameters. Returns the sent message in the requested format when successful.
1654
     *
1655
     *
1656
     * @param    string $text The text of your direct message. Be sure to URL encode as necessary, and keep it under 140 characters.
1657
     * @param null      $id
1658
     * @param null      $userId
1659
     * @param null      $screenName
1660
     * @return array
1661
     * @throws TwitterException
1662
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1663
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1664
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1665
     */
1666 View Code Duplication
    public function directMessagesNew($text, $id = null, $userId = null, $screenName = null)
0 ignored issues
show
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...
1667
    {
1668
        // validate
1669
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
1670
1671
        // build parameters
1672
        $parameters['text'] = (string)$text;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1673
        if ($id != null) $parameters['user'] = (string)$id;
1674
        if ($userId != null) $parameters['user_id'] = (string)$userId;
1675
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1676
1677
        // make the call
1678
        return (array)$this->doCall('direct_messages/new.json', $parameters, true, 'POST');
1679
    }
1680
1681
    /**
1682
     * Destroys the direct message specified in the required ID parameter. The authenticating user must be the recipient of the specified direct message.
1683
     *
1684
     * @return    array
1685
     * @param    string $id The ID of the desired direct message.
1686
     */
1687
    public function directMessagesDestroy($id)
1688
    {
1689
        // build parameters
1690
        $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1691
1692
        // make the call
1693
        return (array)$this->doCall('direct_messages/destroy.json', $parameters, true, 'POST');
1694
    }
1695
1696
1697
    // Friendship resources
1698
    /**
1699
     * Allows the authenticating users to follow the user specified in the ID parameter.
1700
     * Returns the befriended user in the requested format when successful.
1701
     * Returns a string describing the failure condition when unsuccessful.
1702
     *
1703
     *
1704
     * @param null $id
1705
     * @param null $userId
1706
     * @param null $screenName
1707
     * @param bool $follow
1708
     * @return mixed
1709
     * @throws TwitterException
1710
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1711
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1712
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1713
     * @internal param $bool [optional] $follow            Returns public statuses that reference the given set of users.
1714
     */
1715 View Code Duplication
    public function friendshipsCreate($id = null, $userId = null, $screenName = null, $follow = false)
0 ignored issues
show
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...
1716
    {
1717
        // validate
1718
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
1719
1720
        // build parameters
1721
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1722
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
1723
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1724
        $parameters['follow'] = $follow ? 'true' : 'false';
1725
1726
        // make the call
1727
        return (array)$this->doCall('friendships/create.json', $parameters, true, 'POST');
1728
    }
1729
1730
    /**
1731
     * Allows the authenticating users to unfollow the user specified in the ID parameter.
1732
     * Returns the unfollowed user in the requested format when successful. Returns a string describing the failure condition when unsuccessful.
1733
     *
1734
     *
1735
     * @param null $id
1736
     * @param null $userId
1737
     * @param null $screenName
1738
     * @return array
1739
     * @throws TwitterException
1740
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1741
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1742
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1743
     */
1744
    public function friendshipsDestroy($id = null, $userId = null, $screenName = null)
1745
    {
1746
        // validate
1747
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
1748
1749
        // build parameters
1750
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1751
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
1752
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1753
1754
        // make the call
1755
        return (array)$this->doCall('friendships/destroy.json', $parameters, true, 'POST');
1756
    }
1757
1758
    /**
1759
     * Tests for the existence of friendship between two users. Will return true if user_a follows user_b, otherwise will return false.
1760
     *
1761
     * @return    bool
1762
     * @param    string $userA The ID or screen_name of the subject user.
1763
     * @param    string $userB The ID or screen_name of the user to test for following.
1764
     */
1765
    public function friendshipsExists($userA, $userB)
1766
    {
1767
        // build parameters
1768
        $parameters['user_a'] = (string)$userA;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1769
        $parameters['user_b'] = (string)$userB;
1770
1771
        // make the call
1772
        return (bool)$this->doCall('friendships/exists.json', $parameters);
0 ignored issues
show
The method doCall() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1773
    }
1774
1775
    /**
1776
     * Returns detailed information about the relationship between two users.
1777
     *
1778
     *
1779
     * @param null $sourceId
1780
     * @param null $sourceScreenName
1781
     * @param null $targetId
1782
     * @param null $targetScreenName
1783
     * @return array
1784
     * @throws TwitterException
1785
     * @internal param $string [optional] $sourceId                The user_id of the subject user.
1786
     * @internal param $string [optional] $sourceScreenName        The screen_name of the subject user.
1787
     * @internal param $string [optional] $targetId                The screen_name of the subject user.
1788
     * @internal param $string [optional] $targetScreenName        The screen_name of the target user.
1789
     */
1790
    public function friendshipsShow($sourceId = null, $sourceScreenName = null, $targetId = null, $targetScreenName = null)
1791
    {
1792
        // validate
1793
        if ($sourceId == '' && $sourceScreenName == '') throw new TwitterException('Specify an sourceId or a sourceScreenName.');
1794
        if ($targetId == '' && $targetScreenName == '') throw new TwitterException('Specify an targetId or a targetScreenName.');
1795
1796
        // build parameters
1797
        if ($sourceId != null) $parameters['source_id'] = (string)$sourceId;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1798
        if ($sourceScreenName != null) $parameters['source_screen_name'] = (string)$sourceScreenName;
0 ignored issues
show
The variable $parameters 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...
1799
        if ($targetId != null) $parameters['target_id'] = (string)$targetId;
1800
        if ($targetScreenName != null) $parameters['target_screen_name'] = (string)$targetScreenName;
1801
1802
        // make the call
1803
        return (array)$this->doCall('friendships/show.json', $parameters);
1804
    }
1805
1806
    /**
1807
     * Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user.
1808
     *
1809
     * @return    array
1810
     * @param    string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1811
     */
1812
    public function friendshipsIncoming($cursor = null)
1813
    {
1814
        $parameters = null;
1815
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1816
1817
        // make the call
1818
        return (array)$this->doCall('friendships/incoming.json', $parameters, true);
1819
    }
1820
1821
    /**
1822
     * Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request.
1823
     *
1824
     * @return    array
1825
     * @param    string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1826
     */
1827
    public function friendshipsOutgoing($cursor = null)
1828
    {
1829
        $parameters = null;
1830
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1831
1832
        // make the call
1833
        return (array)$this->doCall('friendships/outgoing.json', $parameters, true);
1834
    }
1835
1836
1837
    // Friends and Followers resources
1838
    /**
1839
     * Returns an array of numeric IDs for every user the specified user is following.
1840
     *
1841
     *
1842
     * @param null $id
1843
     * @param null $userId
1844
     * @param null $screenName
1845
     * @param null $cursor
1846
     * @return array
1847
     * @throws TwitterException
1848
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1849
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1850
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1851
     * @internal param $string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1852
     */
1853 View Code Duplication
    public function friendsIds($id = null, $userId = null, $screenName = null, $cursor = null)
0 ignored issues
show
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...
1854
    {
1855
        // validate
1856
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
1857
1858
        // build parameters
1859
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1860
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
1861
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1862
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1863
1864
        // make the call
1865
        return (array)$this->doCall('friends/ids.json', $parameters);
1866
    }
1867
1868
    /**
1869
     * Returns an array of numeric IDs for every user following the specified user.
1870
     *
1871
     *
1872
     * @param null $id
1873
     * @param null $userId
1874
     * @param null $screenName
1875
     * @param null $cursor
1876
     * @return array
1877
     * @throws TwitterException
1878
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
1879
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
1880
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
1881
     * @internal param $string [optional] $cursor    Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1  to begin paging. Provide values as returned to in the response body's next_cursor  and previous_cursor attributes to page back and forth in the list.
1882
     */
1883 View Code Duplication
    public function followersIds($id = null, $userId = null, $screenName = null, $cursor = null)
0 ignored issues
show
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...
1884
    {
1885
        // validate
1886
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
1887
1888
        // build parameters
1889
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1890
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
1891
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
1892
        if ($cursor != null) $parameters['cursor'] = (string)$cursor;
1893
1894
        // make the call
1895
        return (array)$this->doCall('followers/ids.json', $parameters);
1896
    }
1897
1898
1899
    // Account resources
1900
    /**
1901
     * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid.
1902
     *
1903
     * @return    array
1904
     */
1905
    public function accountVerifyCredentials()
1906
    {
1907
        // make the call
1908
        return (array)$this->doCall('account/verify_credentials.json', null, true);
1909
    }
1910
1911
    /**
1912
     *
1913
     * @return    array
1914
     */
1915
    public function accountRateLimitStatus()
1916
    {
1917
        // make the call
1918
        return (array)$this->doCall('account/rate_limit_status.json', null);
1919
    }
1920
1921
    /**
1922
     * Ends the session of the authenticating user, returning a null cookie. Use this method to sign users out of client-facing applications like widgets.
1923
     * @return bool
1924
     * @throws TwitterException
1925
     */
1926
    public function accountEndSession()
1927
    {
1928
        try {
1929
            // make the call
1930
            $this->doCall('account/end_session.json', null, true, 'POST');
0 ignored issues
show
The method doCall() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1931
        } // catch exceptions
1932
        catch (TwitterException $e) {
1933
            if ($e->getMessage() === 'Logged out.') {
1934
                return true;
1935
            } else throw $e;
1936
        }
1937
    }
1938
1939
    /**
1940
     * Sets which device Twitter delivers updates to for the authenticating user. Sending none as the device parameter will disable IM or SMS updates.
1941
     *
1942
     * @return    array
1943
     * @param    string $device Delivery device type to send updates to.
1944
     */
1945
    public function accountUpdateDeliveryDevices($device)
1946
    {
1947
        // build parameters
1948
        $parameters['device'] = (string)$device;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1949
1950
        // make the call
1951
        return (array)$this->doCall('account/update_delivery_device.json', $parameters, true, 'POST');
1952
    }
1953
1954
    /**
1955
     * Sets one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com.
1956
     * Each parameter's value must be a valid hexidecimal value, and may be either three or six characters (ex: #fff or #ffffff).
1957
     *
1958
     *
1959
     * @param null $profileBackgroundColor
1960
     * @param null $profileTextColor
1961
     * @param null $profileLinkColor
1962
     * @param null $profileSidebarFillColor
1963
     * @param null $profileSidebarBorderColor
1964
     * @return array
1965
     * @throws TwitterException
1966
     * @internal param $string [optional] $profileBackgroundColor        Profile background color.
1967
     * @internal param $string [optional] $profileTextColor                Profile text color.
1968
     * @internal param $string [optional] $profileLinkColor                Profile link color.
1969
     * @internal param $string [optional] $profileSidebarFillColor        Profile sidebar's background color.
1970
     * @internal param $string [optional] $profileSidebarBorderColor        Profile sidebar's border color.
1971
     */
1972
    public function accountUpdateProfileColors($profileBackgroundColor = null, $profileTextColor = null, $profileLinkColor = null, $profileSidebarFillColor = null, $profileSidebarBorderColor = null)
1973
    {
1974
        // validate
1975
        if ($profileBackgroundColor == '' && $profileTextColor == '' && $profileLinkColor == '' && $profileSidebarFillColor == ''
1976
            && $profileSidebarBorderColor == ''
1977
        ) throw new TwitterException('Specify a profileBackgroundColor, profileTextColor, profileLinkColor, profileSidebarFillColor or a profileSidebarBorderColor.');
1978
1979
        // build parameters
1980
        if ($profileBackgroundColor != null) $parameters['profile_background_color'] = (string)$profileBackgroundColor;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1981
        if ($profileTextColor != null) $parameters['profile_text_color'] = (string)$profileTextColor;
0 ignored issues
show
The variable $parameters 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...
1982
        if ($profileLinkColor != null) $parameters['profile_link_color'] = (string)$profileLinkColor;
1983
        if ($profileSidebarFillColor != null) $parameters['profile_sidebar_fill_color'] = (string)$profileSidebarFillColor;
1984
        if ($profileSidebarBorderColor != null) $parameters['profile_sidebar_border_color'] = (string)$profileSidebarBorderColor;
1985
1986
        // make the call
1987
        return (array)$this->doCall('account/update_profile_colors.json', $parameters, true, 'POST');
1988
    }
1989
1990
    /**
1991
     * Updates the authenticating user's profile image.
1992
     *
1993
     *
1994
     * @param    string $image The path to the avatar image for the profile. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down.
1995
     * @return array
1996
     * @throws TwitterException
1997
     */
1998
    public function accountUpdateProfileImage($image)
1999
    {
2000
        throw new TwitterException('Not implemented');
2001
2002
        // validate
2003
        if (!file_exists($image)) throw new TwitterException('Image (' . $image . ') doesn\'t exists.');
0 ignored issues
show
if (!file_exists($image)...) doesn\'t exists.'); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
2004
2005
        // make the call
2006
        return (array)$this->doCall('account/update_profile_image.json', null, true, 'POST', $image);
2007
    }
2008
2009
    /**
2010
     * Updates the authenticating user's profile background image.
2011
     *
2012
     *
2013
     * @param    string $image The path to the background image for the profile. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forceably scaled down.
2014
     * @param    bool   $tile  Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
2015
     * @return array
2016
     * @throws TwitterException
2017
     */
2018
    public function accountUpdateProfileBackgroundImage($image, $tile = false)
2019
    {
2020
        throw new TwitterException('Not implemented');
2021
2022
        // validate
2023
        if (!file_exists($image)) throw new TwitterException('Image (' . $image . ') doesn\'t exists.');
0 ignored issues
show
if (!file_exists($image)...) doesn\'t exists.'); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
2024
2025
        // build parameters
2026
        if ($tile) $parameters['tile'] = 'true';
2027
2028
        // make the call
2029
        return (array)$this->doCall('account/update_profile_background_image.json', $parameters, true, 'POST', $image);
2030
    }
2031
2032
    /**
2033
     * Sets values that users are able to set under the "Account" tab of their settings page. Only the parameters specified will be updated.
2034
     *
2035
     * @return    array
2036
     * @param    string [optional] $name            Full name associated with the profile. Maximum of 20 characters.
2037
     * @param    string [optional] $url            URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
2038
     * @param    string [optional] $location        The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
2039
     * @param    string [optional] $description    A description of the user owning the account. Maximum of 160 characters.
2040
     */
2041
    public function accountUpdateProfile($name = null, $url = null, $location = null, $description = null)
2042
    {
2043
        // build parameters
2044
        $parameters = null;
2045
        if ($name != null) $parameters['name'] = (string)$name;
2046
        if ($url != null) $parameters['url'] = (string)$url;
2047
        if ($location != null) $parameters['location'] = (string)$location;
2048
        if ($description != null) $parameters['description'] = (string)$description;
2049
2050
        // make the call
2051
        return (array)$this->doCall('account/update_profile.json', $parameters, true, 'POST');
2052
    }
2053
2054
2055
    // Favorites resources
2056
    /**
2057
     * Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format.
2058
     *
2059
     * @return    array
2060
     * @param    string [optional] $id    Specifies the ID or screen name of the user for whom to return results for.
2061
     * @param    int    [optional] $page        Specifies the page of results to retrieve.
2062
     */
2063 View Code Duplication
    public function favorites($id = null, $page = null)
0 ignored issues
show
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...
2064
    {
2065
        // build parameters
2066
        $parameters = null;
2067
        if ($id != null) $parameters['id'] = (string)$id;
2068
        if ($page != null) $parameters['page'] = (int)$page;
2069
2070
        // make the call
2071
        return (array)$this->doCall('favorites.json', $parameters, true);
2072
    }
2073
2074
    /**
2075
     * Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.
2076
     *
2077
     * @return    array
2078
     * @param    string $id The numerical ID of the desired status.
2079
     */
2080
    public function favoritesCreate($id)
2081
    {
2082
        // make the call
2083
        return (array)$this->doCall('favorites/create/' . $id . '.json', null, true, 'POST');
2084
    }
2085
2086
    /**
2087
     * Un-favorites the status specified in the ID parameter as the authenticating user. Returns the un-favorited status in the requested format when successful.
2088
     *
2089
     * @return    array
2090
     * @param    string $id The numerical ID of the desired status.
2091
     */
2092
    public function favoritesDestroy($id)
2093
    {
2094
        // make the call
2095
        return (array)$this->doCall('favorites/destroy/' . $id . '.json', null, true, 'POST');
2096
    }
2097
2098
2099
    // Notification resources
2100
    /**
2101
     * Enables device notifications for updates from the specified user. Returns the specified user when successful.
2102
     *
2103
     *
2104
     * @param null $id
2105
     * @param null $userId
2106
     * @param null $screenName
2107
     * @return array
2108
     * @throws TwitterException
2109
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
2110
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
2111
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
2112
     */
2113
    public function notificationsFollow($id = null, $userId = null, $screenName = null)
2114
    {
2115
        // validate
2116
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
2117
2118
        // build parameters
2119
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2120
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
2121
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
2122
2123
        // make the call
2124
        return (array)$this->doCall('notifications/follow.json', $parameters, true, 'POST');
2125
    }
2126
2127
    /**
2128
     * Disables notifications for updates from the specified user to the authenticating user. Returns the specified user when successful.
2129
     *
2130
     *
2131
     * @param null $id
2132
     * @param null $userId
2133
     * @param null $screenName
2134
     * @return array
2135
     * @throws TwitterException
2136
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
2137
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
2138
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
2139
     */
2140
    public function notificationsLeave($id = null, $userId = null, $screenName = null)
2141
    {
2142
        // validate
2143
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
2144
2145
        // build parameters
2146
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2147
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
2148
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
2149
2150
        // make the call
2151
        return (array)$this->doCall('notifications/leave.json', $parameters, true, 'POST');
2152
    }
2153
2154
2155
    // Block resources
2156
    /**
2157
     * Blocks the user specified in the ID parameter as the authenticating user. Destroys a friendship to the blocked user if it exists. Returns the blocked user in the requested format when successful.
2158
     *
2159
     *
2160
     * @param null $id
2161
     * @param null $userId
2162
     * @param null $screenName
2163
     * @return array
2164
     * @throws TwitterException
2165
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
2166
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
2167
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
2168
     */
2169
    public function blocksCreate($id = null, $userId = null, $screenName = null)
2170
    {
2171
        // validate
2172
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
2173
2174
        // build parameters
2175
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2176
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
2177
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
2178
2179
        // make the call
2180
        return (array)$this->doCall('blocks/create.json', $parameters, true, 'POST');
2181
    }
2182
2183
    /**
2184
     * Un-blocks the user specified in the ID parameter for the authenticating user. Returns the un-blocked user in the requested format when successful.
2185
     *
2186
     *
2187
     * @param null $id
2188
     * @param null $userId
2189
     * @param null $screenName
2190
     * @return array
2191
     * @throws TwitterException
2192
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
2193
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
2194
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
2195
     */
2196
    public function blocksDestroy($id = null, $userId = null, $screenName = null)
2197
    {
2198
        // validate
2199
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
2200
2201
        // build parameters
2202
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2203
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
2204
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
2205
2206
        // make the call
2207
        return (array)$this->doCall('blocks/destroy.json', $parameters, true, 'POST');
2208
    }
2209
2210
    /**
2211
     * Un-blocks the user specified in the ID parameter for the authenticating user. Returns the un-blocked user in the requested format when successful.
2212
     *
2213
     *
2214
     * @param null $id
2215
     * @param null $userId
2216
     * @param null $screenName
2217
     * @return mixed
2218
     * @throws TwitterException
2219
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
2220
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
2221
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
2222
     */
2223
    public function blocksExists($id = null, $userId = null, $screenName = null)
2224
    {
2225
        // validate
2226
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
2227
2228
        // build parameters
2229
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2230
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
2231
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
2232
2233
        try {
2234
            // make the call
2235
            return (array)$this->doCall('blocks/exists.json', $parameters, true);
2236
        } // catch exceptions
2237
        catch (TwitterException $e) {
2238
            if ($e->getMessage() === 'You are not blocking this user.') {
2239
                return false;
2240
            } else throw $e;
2241
        }
2242
    }
2243
2244
    /**
2245
     * Returns an array of user objects that the authenticating user is blocking.
2246
     *
2247
     * @return    array
2248
     * @param    int [optional] $page        Specifies the page of results to retrieve. Note: there are pagination limits. See the FAQ for details.
2249
     */
2250
    public function blocksBlocking($page = null)
2251
    {
2252
        // build parameters
2253
        $parameters = null;
2254
        if ($page != null) $parameters['page'] = (int)$page;
2255
2256
        // make the call
2257
        return (array)$this->doCall('blocks/blocking.json', $parameters, true);
2258
    }
2259
2260
    /**
2261
     * Returns an array of numeric user ids the authenticating user is blocking.
2262
     *
2263
     * @return    array
2264
     */
2265
    public function blocksBlockingIds()
2266
    {
2267
        // make the call
2268
        return (array)$this->doCall('blocks/blocking/ids.json', null, true);
2269
    }
2270
2271
2272
    // Spam Reporting resources
2273
    /**
2274
     * The user specified in the id is blocked by the authenticated user and reported as a spammer.
2275
     *
2276
     *
2277
     * @param null $id
2278
     * @param null $userId
2279
     * @param null $screenName
2280
     * @return array
2281
     * @throws TwitterException
2282
     * @internal param $string [optional] $id            Specifies the ID or screen name of the user for whom to return results for.
2283
     * @internal param $string [optional] $userId        Specfies the screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.
2284
     * @internal param $string [optional] $screenName    Specfies the ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.
2285
     */
2286
    public function reportSpam($id = null, $userId = null, $screenName = null)
2287
    {
2288
        // validate
2289
        if ($id == '' && $userId == '' && $screenName == '') throw new TwitterException('Specify an id or an userId or a screenName.');
2290
2291
        // build parameters
2292
        if ($id != null) $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2293
        if ($userId != null) $parameters['user_id'] = (string)$userId;
0 ignored issues
show
The variable $parameters 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...
2294
        if ($screenName != null) $parameters['screen_name'] = (string)$screenName;
2295
2296
        // make the call
2297
        return (array)$this->doCall('report_spam.json', $parameters, true, 'POST');
2298
    }
2299
2300
2301
    // Saved Searches resources
2302
    /**
2303
     * Returns the authenticated user's saved search queries.
2304
     *
2305
     * @return    array
2306
     */
2307
    public function savedSearches()
2308
    {
2309
        // make the call
2310
        return (array)$this->doCall('saved_searches.json', null, true);
2311
    }
2312
2313
    /**
2314
     * Retrieve the data for a saved search owned by the authenticating user specified by the given id.
2315
     *
2316
     * @return    array
2317
     * @param    string $id The ID of the desired saved search.
2318
     */
2319
    public function savedSearchesShow($id)
2320
    {
2321
        // build parameters
2322
        $parameters['id'] = (string)$id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2323
2324
        // make the call
2325
        return (array)$this->doCall('saved_searches/show.json', $parameters, true);
2326
    }
2327
2328
    /**
2329
     * Creates a saved search for the authenticated user.
2330
     *
2331
     * @return    array
2332
     * @param    string $query The query of the search the user would like to save.
2333
     */
2334
    public function savedSearchesCreate($query)
2335
    {
2336
        // build parameters
2337
        $parameters['query'] = (string)$query;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2338
2339
        // make the call
2340
        return (array)$this->doCall('saved_searches/create.json', $parameters, true, 'POST');
2341
    }
2342
2343
    /**
2344
     * Destroys a saved search for the authenticated user. The search specified by id must be owned by the authenticating user.
2345
     * REMARK: This method seems not to work    @later
2346
     *
2347
     * @return    array
2348
     * @param    string $id The ID of the desired saved search.
2349
     */
2350
    public function savedSearchesDestroy($id)
2351
    {
2352
        return (array)$this->doCall('saved_searches/destroy/' . (string)$id . '.json', null, true, 'POST');
2353
    }
2354
2355
2356
    // OAuth resources
2357
    /**
2358
     * Allows a Consumer application to obtain an OAuth Request Token to request user authorization.
2359
     * This method fulfills Secion 6.1 of the OAuth 1.0 authentication flow.
2360
     *
2361
     *
2362
     * @param    string $callbackURL
2363
     * @return array An array containg the token and the secret
2364
     * @throws TwitterException
2365
     */
2366
    public function oAuthRequestToken($callbackURL = null)
2367
    {
2368
        // init var
2369
        $parameters = array();
2370
2371
        // set callback
2372
        if ($callbackURL != null) $parameters['oauth_callback'] = (string)$callbackURL;
0 ignored issues
show
It seems like you are loosely comparing $callbackURL of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
2373
2374
        // make the call
2375
        $response = $this->doOAuthCall('request_token', $parameters);
0 ignored issues
show
The method doOAuthCall() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2376
2377
        // validate
2378
        if (!isset($response['oauth_token'], $response['oauth_token_secret'])) throw new TwitterException(implode(', ', array_keys($response)));
2379
2380
        // set some properties
2381
        if (isset($response['oauth_token'])) $this->setOAuthToken($response['oauth_token']);
0 ignored issues
show
The method setOAuthToken() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2382
        if (isset($response['oauth_token_secret'])) $this->setOAuthTokenSecret($response['oauth_token_secret']);
0 ignored issues
show
The method setOAuthTokenSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2383
2384
        // return
2385
        return $response;
2386
    }
2387
2388
    /**
2389
     * Allows a Consumer application to exchange the OAuth Request Token for an OAuth Access Token.
2390
     * This method fulfills Secion 6.3 of the OAuth 1.0 authentication flow.
2391
     *
2392
     * @return    array
2393
     * @param    string $token
2394
     * @param    string $verifier
2395
     */
2396
    public function oAuthAccessToken($token, $verifier)
2397
    {
2398
        // init var
2399
        $parameters                   = array();
2400
        $parameters['oauth_token']    = (string)$token;
2401
        $parameters['oauth_verifier'] = (string)$verifier;
2402
2403
        // make the call
2404
        $response = $this->doOAuthCall('access_token', $parameters);
0 ignored issues
show
The method doOAuthCall() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2405
2406
        // set some properties
2407
        if (isset($response['oauth_token'])) $this->setOAuthToken($response['oauth_token']);
0 ignored issues
show
The method setOAuthToken() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2408
        if (isset($response['oauth_token_secret'])) $this->setOAuthTokenSecret($response['oauth_token_secret']);
0 ignored issues
show
The method setOAuthTokenSecret() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2409
2410
        // return
2411
        return $response;
2412
    }
2413
2414
    /**
2415
     * Will redirect to the page to authorize the applicatione
2416
     *
2417
     * @return    void
2418
     */
2419
    public function oAuthAuthorize()
2420
    {
2421
        header('Location: ' . self::SECURE_API_URL . '/oauth/authorize?oauth_token=' . $this->oAuthToken);
2422
    }
2423
2424
    /**
2425
     * Allows a Consumer application to use an OAuth request_token to request user authorization. This method is a replacement fulfills Secion 6.2 of the OAuth 1.0 authentication flow for applications using the Sign in with Twitter authentication flow. The method will use the currently logged in user as the account to for access authorization unless the force_login parameter is set to true
2426
     * REMARK: This method seems not to work    @later
2427
     *
2428
     * @return    void
2429
     */
2430
    public function oAuthAuthenticate()
2431
    {
2432
        // make the call
2433
        return $this->doOAuthCall('authenticate');
0 ignored issues
show
The method doOAuthCall() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2434
    }
2435
2436
2437
    // Local Trends resources
2438
    /**
2439
     * Returns the locations that Twitter has trending topic information for.
2440
     * The response is an array of "locations" that encode the location's WOEID (a Yahoo! Where On Earth ID) and some other human-readable information such as a canonical name and country the location belongs in.
2441
     * The WOEID that is returned in the location object is to be used when querying for a specific trend.
2442
     *
2443
     * @return    array
2444
     * @param    float [optional] $lat    If passed in conjunction with long, then the available trend locations will be sorted by distance to the lat  and long passed in. The sort is nearest to furthest.
2445
     * @param    float [optional] $long    If passed in conjunction with lat, then the available trend locations will be sorted by distance to the lat  and long passed in. The sort is nearest to furthest.
2446
     */
2447 View Code Duplication
    public function trendsAvailable($lat = null, $long = null)
0 ignored issues
show
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...
2448
    {
2449
        // build parameters
2450
        $parameters = null;
2451
        if ($lat != null) $parameters['lat_for_trends'] = (float)$lat;
2452
        if ($long != null) $parameters['long_for_trends'] = (float)$long;
2453
2454
        // make the call
2455
        return (array)$this->doCall('trends/available.json', $parameters);
2456
    }
2457
2458
    /**
2459
     * Returns the top 10 trending topics for a specific location Twitter has trending topic information for.
2460
     * The response is an array of "trend" objects that encode the name of the trending topic, the query parameter that can be used to search for the topic on Search, and the direct URL that can be issued against Search.
2461
     * This information is cached for five minutes, and therefore users are discouraged from querying these endpoints faster than once every five minutes. Global trends information is also available from this API by using a WOEID of 1.
2462
     * REMARK: This method seems not to work    @later
2463
     *
2464
     * @return    array
2465
     * @param    string $woeid The WOEID of the location to be querying for.
2466
     */
2467
    public function trendsLocation($woeid)
2468
    {
2469
        // make the call
2470
        return (array)$this->doCall('trends/location/' . (string)$woeid . '.json');
2471
    }
2472
2473
2474
    // Geo resources
2475
    /**
2476
     * Search for places (cities and neighborhoods) that can be attached to a statuses/update. Given a latitude and a longitude, return a list of all the valid places that can be used as a place_id when updating a status.
2477
     * Conceptually, a query can be made from the user's location, retrieve a list of places, have the user validate the location he or she is at, and then send the ID of this location up with a call to statuses/update.
2478
     * There are multiple granularities of places that can be returned -- "neighborhoods", "cities", etc. At this time, only United States data is available through this method.
2479
     * This API call is meant to be an informative call and will deliver generalized results about geography.
2480
     *
2481
     * @return    array
2482
     * @param    float $lat   The location's latitude that this tweet refers to.
2483
     * @param    float $long  The location's longitude that this tweet refers to.
2484
     * @param          string [optional] $accuracy        A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If this is not passed in, then it is assumed to be 0m. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
2485
     * @param          string [optional] $granularity    The minimal granularity of data to return. If this is not passed in, then neighborhood is assumed. city can also be passed.
2486
     * @param          int    [optional] $maxResults        A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
2487
     */
2488
    public function geoReverseGeoCode($lat, $long, $accuracy = null, $granularity = null, $maxResults = null)
2489
    {
2490
        // build parameters
2491
        $parameters['lat']  = (float)$lat;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2492
        $parameters['long'] = (float)$long;
2493
        if ($accuracy != null) $parameters['accuracy'] = (string)$accuracy;
2494
        if ($granularity != null) $parameters['granularity'] = (string)$granularity;
2495
        if ($maxResults != null) $parameters['max_results'] = (int)$maxResults;
2496
2497
        // make the call
2498
        return (array)$this->doCall('geo/reverse_geocode.json', $parameters);
2499
    }
2500
2501
    /**
2502
     * Find out more details of a place that was returned from the geo/reverse_geocode method.
2503
     *
2504
     * @return    array
2505
     * @param    string $id
2506
     * @param           string [optional] $placeId    A place in the world. These IDs can be retrieved from geo/reverse_geocode.
2507
     */
2508
    public function geoId($id, $placeId = null)
2509
    {
2510
        // build parameters
2511
        $parameters = null;
2512
        if ($placeId != null) $parameters['place_id'] = (string)$placeId;
2513
2514
        // make the call
2515
        return (array)$this->doCall('geo/id/' . (string)$id . '.json', $parameters);
2516
    }
2517
2518
2519
    // Help resources
2520
    /**
2521
     * Test
2522
     * REMARK: this methods seems not to work, so don't rely on it
2523
     *
2524
     * @return    bool
2525
     */
2526
    public function helpTest()
2527
    {
2528
        // make the call
2529
        return ($this->doCall('help/test', null, null, 'GET', null, false) == 'ok');
0 ignored issues
show
The method doCall() does not seem to exist on object<Twitter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2530
    }
2531
}
2532
2533
/**
2534
 * Twitter Exception class
2535
 *
2536
 * @author    Tijs Verkoyen <[email protected]>
2537
 */
2538
class TwitterException extends Exception
2539
{
2540
}
2541
2542