Skip to content

Commit 161f9ae

Browse files
committed
Use short array syntax
1 parent b7a69a5 commit 161f9ae

File tree

71 files changed

+904
-904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+904
-904
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ if ($curl->error) {
5959
```php
6060
// https://www.example.com/search?q=keyword
6161
$curl = new Curl();
62-
$curl->get('https://www.example.com/search', array(
62+
$curl->get('https://www.example.com/search', [
6363
'q' => 'keyword',
64-
));
64+
]);
6565
```
6666

6767
```php
6868
$curl = new Curl();
69-
$curl->post('https://www.example.com/login/', array(
69+
$curl->post('https://www.example.com/login/', [
7070
'username' => 'myusername',
7171
'password' => 'mypassword',
72-
));
72+
]);
7373
```
7474

7575
```php
@@ -100,31 +100,31 @@ $curl->get('https://shortn.example.com/bHbVsP');
100100

101101
```php
102102
$curl = new Curl();
103-
$curl->put('https://api.example.com/user/', array(
103+
$curl->put('https://api.example.com/user/', [
104104
'first_name' => 'Zach',
105105
'last_name' => 'Borboa',
106-
));
106+
]);
107107
```
108108

109109
```php
110110
$curl = new Curl();
111-
$curl->patch('https://api.example.com/profile/', array(
111+
$curl->patch('https://api.example.com/profile/', [
112112
'image' => '@path/to/file.jpg',
113-
));
113+
]);
114114
```
115115

116116
```php
117117
$curl = new Curl();
118-
$curl->patch('https://api.example.com/profile/', array(
118+
$curl->patch('https://api.example.com/profile/', [
119119
'image' => new CURLFile('path/to/file.jpg'),
120-
));
120+
]);
121121
```
122122

123123
```php
124124
$curl = new Curl();
125-
$curl->delete('https://api.example.com/user/', array(
125+
$curl->delete('https://api.example.com/user/', [
126126
'id' => '1234',
127-
));
127+
]);
128128
```
129129

130130
```php
@@ -175,15 +175,15 @@ $multi_curl->complete(function($instance) {
175175
echo 'call completed' . "\n";
176176
});
177177

178-
$multi_curl->addGet('https://www.google.com/search', array(
178+
$multi_curl->addGet('https://www.google.com/search', [
179179
'q' => 'hello world',
180-
));
181-
$multi_curl->addGet('https://duckduckgo.com/', array(
180+
]);
181+
$multi_curl->addGet('https://duckduckgo.com/', [
182182
'q' => 'hello world',
183-
));
184-
$multi_curl->addGet('https://www.bing.com/search', array(
183+
]);
184+
$multi_curl->addGet('https://www.bing.com/search', [
185185
'q' => 'hello world',
186-
));
186+
]);
187187

188188
$multi_curl->start(); // Blocks until all items in the queue have been processed.
189189
```
@@ -202,13 +202,13 @@ Curl::buildPostData($data)
202202
Curl::call()
203203
Curl::close()
204204
Curl::complete($callback)
205-
Curl::delete($url, $query_parameters = array(), $data = array())
205+
Curl::delete($url, $query_parameters = [], $data = [])
206206
Curl::disableTimeout()
207207
Curl::download($url, $mixed_filename)
208208
Curl::error($callback)
209209
Curl::exec($ch = null)
210210
Curl::execDone()
211-
Curl::get($url, $data = array())
211+
Curl::get($url, $data = [])
212212
Curl::getAttempts()
213213
Curl::getBeforeSendCallback()
214214
Curl::getCompleteCallback()
@@ -241,19 +241,19 @@ Curl::getRetryDecider()
241241
Curl::getSuccessCallback()
242242
Curl::getUrl()
243243
Curl::getXmlDecoder()
244-
Curl::head($url, $data = array())
244+
Curl::head($url, $data = [])
245245
Curl::isChildOfMultiCurl()
246246
Curl::isCurlError()
247247
Curl::isError()
248248
Curl::isHttpError()
249-
Curl::options($url, $data = array())
250-
Curl::patch($url, $data = array())
249+
Curl::options($url, $data = [])
250+
Curl::patch($url, $data = [])
251251
Curl::post($url, $data = '', $follow_303_with_post = false)
252252
Curl::progress($callback)
253-
Curl::put($url, $data = array())
253+
Curl::put($url, $data = [])
254254
Curl::removeHeader($key)
255255
Curl::reset()
256-
Curl::search($url, $data = array())
256+
Curl::search($url, $data = [])
257257
Curl::setBasicAuthentication($username, $password = '')
258258
Curl::setConnectTimeout($seconds)
259259
Curl::setCookie($key, $value)
@@ -295,15 +295,15 @@ Curl::verbose($on = true, $output = 'STDERR')
295295
MultiCurl::__construct($base_url = null)
296296
MultiCurl::__destruct()
297297
MultiCurl::addCurl(Curl $curl)
298-
MultiCurl::addDelete($url, $query_parameters = array(), $data = array())
298+
MultiCurl::addDelete($url, $query_parameters = [], $data = [])
299299
MultiCurl::addDownload($url, $mixed_filename)
300-
MultiCurl::addGet($url, $data = array())
301-
MultiCurl::addHead($url, $data = array())
302-
MultiCurl::addOptions($url, $data = array())
303-
MultiCurl::addPatch($url, $data = array())
300+
MultiCurl::addGet($url, $data = [])
301+
MultiCurl::addHead($url, $data = [])
302+
MultiCurl::addOptions($url, $data = [])
303+
MultiCurl::addPatch($url, $data = [])
304304
MultiCurl::addPost($url, $data = '', $follow_303_with_post = false)
305-
MultiCurl::addPut($url, $data = array())
306-
MultiCurl::addSearch($url, $data = array())
305+
MultiCurl::addPut($url, $data = [])
306+
MultiCurl::addSearch($url, $data = [])
307307
MultiCurl::beforeSend($callback)
308308
MultiCurl::close()
309309
MultiCurl::complete($callback)

SECURITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ echo $curl->response;
2121
Safer:
2222

2323
```php
24-
function is_allowed_url($url, $allowed_url_schemes = array('http', 'https')) {
24+
function is_allowed_url($url, $allowed_url_schemes = ['http', 'https']) {
2525
$valid_url = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED) !== false;
2626
if ($valid_url) {
2727
$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -54,9 +54,9 @@ $ curl https://www.example.com/upload_photo.php --data "photo=@/etc/passwd"
5454
```php
5555
// upload_photo.php
5656
$curl = new Curl();
57-
$curl->post('http://www.anotherwebsite.com/', array(
57+
$curl->post('http://www.anotherwebsite.com/', [
5858
'photo' => $_POST['photo'], // DANGER!
59-
));
59+
]);
6060
```
6161

6262
### Unsafe response with redirection enabled

examples/delete.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
$curl = new Curl();
99
$curl->delete(
1010
'https://httpbin.org/delete',
11-
array(
11+
[
1212
'key' => 'value',
13-
),
14-
array(
13+
],
14+
[
1515
'a' => '1',
1616
'b' => '2',
1717
'c' => '3',
18-
)
18+
]
1919
);
2020

2121
if ($curl->error) {

examples/deviant_art_rss.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use Curl\Curl;
55

66
$curl = new Curl();
7-
$curl->get('http://backend.deviantart.com/rss.xml', array(
7+
$curl->get('http://backend.deviantart.com/rss.xml', [
88
'q' => 'boost:popular in:photography/people/fashion',
99
'type' => 'deviation',
10-
));
10+
]);
1111

1212
foreach ($curl->response->channel->item as $entry) {
1313
$thumbnails = $entry->children('http://search.yahoo.com/mrss/')->thumbnail;

examples/flickr.class.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ public function uploadPhoto()
4646

4747
private function getOAuthParameters()
4848
{
49-
return array(
49+
return [
5050
'oauth_nonce' => md5(microtime() . mt_rand()),
5151
'oauth_timestamp' => time(),
5252
'oauth_consumer_key' => FLICKR_API_KEY,
5353
'oauth_signature_method' => 'HMAC-SHA1',
5454
'oauth_version' => '1.0',
55-
);
55+
];
5656
}
5757

5858
private function getSignature($request_method, $url, $parameters)
5959
{
6060
ksort($parameters, SORT_STRING);
61-
$request = implode('&', array(
61+
$request = implode('&', [
6262
rawurlencode($request_method),
6363
rawurlencode($url),
6464
rawurlencode(http_build_query($parameters, '', '&', PHP_QUERY_RFC3986)),
65-
));
65+
]);
6666
$key = FLICKR_API_SECRET . '&';
6767
if (!empty($_SESSION['oauth_access_token_secret'])) {
6868
$key .= $_SESSION['oauth_access_token_secret'];
@@ -76,12 +76,12 @@ private function getSignature($request_method, $url, $parameters)
7676
private function getRequestToken()
7777
{
7878
$oauth_data = $this->getOAuthParameters();
79-
$oauth_data['oauth_callback'] = implode('', array(
79+
$oauth_data['oauth_callback'] = implode('', [
8080
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http',
8181
'://',
8282
$_SERVER['SERVER_NAME'],
8383
$_SERVER['SCRIPT_NAME'],
84-
));
84+
]);
8585

8686
$request_token_url = 'https://www.flickr.com/services/oauth/request_token';
8787
$oauth_data['oauth_signature'] = $this->getSignature('POST', $request_token_url, $oauth_data);
@@ -93,10 +93,10 @@ private function getRequestToken()
9393
$_SESSION['oauth_token_secret'] = $parts['oauth_token_secret'];
9494

9595
// Continue to Flickr for user's authorization.
96-
header('Location: https://secure.flickr.com/services/oauth/authorize?' . http_build_query(array(
96+
header('Location: https://secure.flickr.com/services/oauth/authorize?' . http_build_query([
9797
'oauth_token' => $parts['oauth_token'],
9898
'perms' => 'write',
99-
)));
99+
]));
100100
exit;
101101
}
102102

examples/flickr_photo_search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
const FLICKR_API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
77

8-
$data = array(
8+
$data = [
99
'method' => 'flickr.photos.search',
1010
'api_key' => FLICKR_API_KEY,
1111
'text' => 'happy',
1212
'sort' => 'interestingness-desc',
1313
'safe_search' => '3',
1414
'format' => 'json',
1515
'nojsoncallback' => '1',
16-
);
16+
];
1717

1818
$curl = new Curl();
1919
$curl->get('https://api.flickr.com/services/rest/', $data);

examples/get.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// curl --request GET "https://httpbin.org/get?key=value"
77

88
$curl = new Curl();
9-
$curl->get('https://httpbin.org/get', array(
9+
$curl->get('https://httpbin.org/get', [
1010
'key' => 'value',
11-
));
11+
]);
1212

1313
if ($curl->error) {
1414
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";

examples/get_base_url_1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
$curl = new Curl('https://httpbin.org/get');
77
for ($i = 1; $i <= 10; $i++) {
8-
$curl->get(array(
8+
$curl->get([
99
'page' => $i,
10-
));
10+
]);
1111
// TODO: Do something with result $curl->response.
1212
}

examples/get_base_url_2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
$curl = new Curl();
77
$curl->setUrl('https://httpbin.org/get');
88
for ($i = 1; $i <= 10; $i++) {
9-
$curl->get(array(
9+
$curl->get([
1010
'page' => $i,
11-
));
11+
]);
1212
// TODO: Do something with result $curl->response.
1313
}

examples/get_pages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
$curl = new Curl();
77
for ($i = 1; $i <= 10; $i++) {
8-
$curl->get('https://httpbin.org/get', array(
8+
$curl->get('https://httpbin.org/get', [
99
'page' => $i,
10-
));
10+
]);
1111
// TODO: Do something with result $curl->response.
1212
}

0 commit comments

Comments
 (0)