Skip to content

Commit 7744160

Browse files
committed
Merge pull request #1 from xp-framework/refactor/short-arrays
Use short array syntax / ::class syntax in annotations
2 parents 21024d2 + 80f13e2 commit 7744160

22 files changed

+88
-87
lines changed

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
language: php
44

5+
sudo: false
6+
57
php:
68
- 5.4
79
- 5.5
810
- 5.6
911
- hhvm
1012
- nightly
1113

12-
matrix:
13-
allow_failures:
14-
- php: nightly
15-
1614
before_script:
17-
- wget 'https://github.com/xp-framework/xp-runners/releases/download/v5.2.0/setup' -O - | php
15+
- wget 'https://github.com/xp-framework/xp-runners/releases/download/v5.5.0/setup' -O - | php
1816
- composer install --prefer-dist
1917
- echo "vendor/autoload.php" > composer.pth
2018
- echo "use=vendor/xp-framework/core" > xp.ini

src/main/php/peer/ftp/FtpConnection.class.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public function connect() {
9090
$this->socket->connect($timeout);
9191

9292
// Read banner message
93-
$this->expect($this->getResponse(), array(220));
93+
$this->expect($this->getResponse(), [220]);
9494

9595
// User & password
9696
if ($this->url->getUser()) {
9797
try {
98-
$this->expect($this->sendCommand('USER %s', $this->url->getUser()), array(331));
99-
$this->expect($this->sendCommand('PASS %s', $this->url->getPassword()), array(230));
98+
$this->expect($this->sendCommand('USER %s', $this->url->getUser()), [331]);
99+
$this->expect($this->sendCommand('PASS %s', $this->url->getPassword()), [230]);
100100
} catch (\peer\ProtocolException $e) {
101101
$this->socket->close();
102102
throw new AuthenticationException(sprintf(
@@ -118,7 +118,7 @@ public function connect() {
118118
$this->setupListParser();
119119

120120
// Retrieve root directory
121-
sscanf($this->expect($this->sendCommand('PWD'), array(257)), '"%[^"]"', $dir);
121+
sscanf($this->expect($this->sendCommand('PWD'), [257]), '"%[^"]"', $dir);
122122
$this->root= new FtpDir(strtr($dir, '\\', '/'), $this);
123123

124124
return $this;
@@ -129,7 +129,7 @@ public function connect() {
129129
*
130130
*/
131131
protected function setupListParser() {
132-
$type= $this->expect($this->sendCommand('SYST'), array(215));
132+
$type= $this->expect($this->sendCommand('SYST'), [215]);
133133
if ('Windows_NT' == $type) {
134134
$this->parser= new WindowsFtpListParser();
135135
} else {
@@ -161,8 +161,8 @@ public function close() {
161161
* @return peer.Socket
162162
*/
163163
public function transferSocket() {
164-
$port= $this->expect($this->sendCommand('PASV'), array(227));
165-
$a= $p= array();
164+
$port= $this->expect($this->sendCommand('PASV'), [227]);
165+
$a= $p= [];
166166
sscanf($port, '%*[^(] (%d,%d,%d,%d,%d,%d)', $a[0], $a[1], $a[2], $a[3], $p[0], $p[1]);
167167

168168
// Open transfer socket
@@ -252,7 +252,7 @@ public function listingOf($name, $options= null) {
252252
$transfer->close();
253253
return null;
254254
} else if (150 === $code) { // Listing
255-
$list= array();
255+
$list= [];
256256
while ($line= $transfer->readLine()) {
257257
$list[]= $line;
258258
}
@@ -262,7 +262,7 @@ public function listingOf($name, $options= null) {
262262
if (450 === $code) { // No such file or directory
263263
return null;
264264
} else { // Some FTP servers send an empty directory listing
265-
$this->expect($r, array(226));
265+
$this->expect($r, [226]);
266266
return $list ? $list : null;
267267
}
268268
} else { // Unexpected response

src/main/php/peer/ftp/FtpDir.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function entries() {
4747
* @throws io.IOException in case of an I/O error
4848
*/
4949
public function delete() {
50-
$this->connection->expect($this->connection->sendCommand('RMD %s', $this->name), array(250));
50+
$this->connection->expect($this->connection->sendCommand('RMD %s', $this->name), [250]);
5151
}
5252

5353
/**
@@ -198,7 +198,7 @@ public function getDir($name) {
198198
* @throws peer.ProtocolException in case the created directory cannot be located or is a file
199199
*/
200200
protected function makeDir($name) {
201-
$this->connection->expect($this->connection->sendCommand('MKD %s', $this->name.$name), array(257));
201+
$this->connection->expect($this->connection->sendCommand('MKD %s', $this->name.$name), [257]);
202202

203203
if (!($created= $this->findEntry($name))) {
204204
throw new ProtocolException('MKDIR "'.$name.'" succeeded but could not find created directory afterwards');

src/main/php/peer/ftp/FtpEntry.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public function exists() {
7777
public function rename($to) {
7878
$target= ('/' === $to{0} ? $to : dirname($this->name).'/'.$to);
7979
try {
80-
$this->connection->expect($this->connection->sendCommand('RNFR %s', $this->name), array(350));
81-
$this->connection->expect($this->connection->sendCommand('RNTO %s', $target), array(250));
80+
$this->connection->expect($this->connection->sendCommand('RNFR %s', $this->name), [350]);
81+
$this->connection->expect($this->connection->sendCommand('RNTO %s', $target), [250]);
8282
} catch (\peer\ProtocolException $e) {
8383
throw new \io\IOException('Could not rename '.$this->name.' to '.$to.': '.$e->getMessage());
8484
}
@@ -93,12 +93,12 @@ public function rename($to) {
9393
*/
9494
public function moveTo(FtpDir $to, $name= null) {
9595
try {
96-
$this->connection->expect($this->connection->sendCommand('RNFR %s', $this->name), array(350));
96+
$this->connection->expect($this->connection->sendCommand('RNFR %s', $this->name), [350]);
9797
$this->connection->expect($this->connection->sendCommand(
9898
'RNTO %s%s',
9999
$to->getName(),
100100
$name ? $name : basename($this->name)
101-
), array(250));
101+
), [250]);
102102
} catch (\peer\ProtocolException $e) {
103103
throw new \io\IOException('Could not rename '.$this->name.' to '.$to->getName().': '.$e->getMessage());
104104
}
@@ -134,7 +134,7 @@ public abstract function delete();
134134
* @throws lang.IllegalArgumentException
135135
*/
136136
public function setPermissions($perm) {
137-
static $m= array('r' => 4, 'w' => 2, 'x' => 1, '-' => 0, 't' => 0);
137+
static $m= ['r' => 4, 'w' => 2, 'x' => 1, '-' => 0, 't' => 0];
138138

139139
if (is_string($perm) && 9 == strlen($perm)) {
140140
$this->permissions= (

src/main/php/peer/ftp/FtpEntryList.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class FtpEntryList extends \lang\Object implements \IteratorAggregate {
99
protected
1010
$connection = null,
11-
$list = array(),
11+
$list = [],
1212
$base = '';
1313

1414
/**
@@ -59,9 +59,9 @@ public function isEmpty() {
5959
* @throws lang.FormatException in case an entry cannot be parsed
6060
*/
6161
public function asArray() {
62-
$dotdirs= array($this->base.'./', $this->base.'../');
62+
$dotdirs= [$this->base.'./', $this->base.'../'];
6363

64-
for ($i= 0, $r= array(), $s= sizeof($this->list); $i < $s; $i++) {
64+
for ($i= 0, $r= [], $s= sizeof($this->list); $i < $s; $i++) {
6565
$e= $this->connection->parser->entryFrom($this->list[$i], $this->connection, $this->base);
6666
in_array($e->getName(), $dotdirs) || $r[]= $e;
6767
}

src/main/php/peer/ftp/FtpFile.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FtpFile extends FtpEntry {
1717
* @throws io.IOException in case of an I/O error
1818
*/
1919
public function delete() {
20-
$this->connection->expect($this->connection->sendCommand('DELE %s', $this->name), array(250));
20+
$this->connection->expect($this->connection->sendCommand('DELE %s', $this->name), [250]);
2121
}
2222

2323
/**

src/main/php/peer/ftp/FtpListIterator.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class FtpListIterator extends \lang\Object implements \Iterator {
1212
private
1313
$i= 0,
14-
$v= array(),
14+
$v= [],
1515
$c= null,
1616
$e= null,
1717
$b= '';
@@ -69,7 +69,7 @@ public function rewind() {
6969
* @return bool
7070
*/
7171
public function valid() {
72-
$dotdirs= array($this->b.'./', $this->b.'../');
72+
$dotdirs= [$this->b.'./', $this->b.'../'];
7373
do {
7474
if ($this->i >= sizeof($this->v)) return false;
7575

src/main/php/peer/ftp/FtpTransfer.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ abstract class FtpTransfer extends \lang\Object {
1111
const ASCII = 1;
1212
const BINARY = 2;
1313

14-
protected static $modes= array(
14+
protected static $modes= [
1515
self::ASCII => 'A',
1616
self::BINARY => 'I'
17-
);
17+
];
1818

1919
protected
2020
$remote = null,
@@ -97,7 +97,7 @@ public function start($mode) {
9797
with ($conn= $this->remote->getConnection()); {
9898

9999
// Set mode
100-
$conn->expect($conn->sendCommand('TYPE %s', self::$modes[$mode]), array(200));
100+
$conn->expect($conn->sendCommand('TYPE %s', self::$modes[$mode]), [200]);
101101

102102
// Issue the transfer command
103103
$this->socket= $conn->transferSocket();
@@ -127,7 +127,7 @@ public function start($mode) {
127127
protected function close() {
128128
$this->socket->close();
129129
with ($conn= $this->remote->getConnection()); {
130-
$conn->expect($conn->getResponse(), array(226));
130+
$conn->expect($conn->getResponse(), [226]);
131131
}
132132
}
133133

src/main/php/peer/ftp/FtpTransferStream.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public function __construct(FtpFile $file) {
2626

2727
// Always use binary mode
2828
// Check for "200 Type set to X"
29-
$conn->expect($conn->sendCommand('TYPE I'), array(200));
29+
$conn->expect($conn->sendCommand('TYPE I'), [200]);
3030

3131
// Always use passive mode, just to be sure
3232
// Check for "227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)."
3333
$this->socket= $conn->transferSocket();
3434

3535
// Begin transfer depending on the direction returned by getCommand()
3636
// Check for "150 Opening XXX mode data connection for ..."
37-
$conn->expect($conn->sendCommand($cmd.' '.$file->getName()), array(150));
37+
$conn->expect($conn->sendCommand($cmd.' '.$file->getName()), [150]);
3838
}
3939
$this->file= $file;
4040
}
@@ -68,7 +68,7 @@ public function close() {
6868
// Reset mode to ASCII
6969
with ($conn= $this->file->getConnection()); {
7070
$r= $conn->getResponse();
71-
$conn->expect($conn->sendCommand('TYPE A'), array(200));
71+
$conn->expect($conn->sendCommand('TYPE A'), [200]);
7272
sscanf($r[0], "%d %[^\r\n]", $code, $message);
7373
if (226 != $code) {
7474
throw new \peer\ProtocolException('Transfer incomplete ('.$code.': '.$message.')');

src/main/php/peer/ftp/server/FtpProtocol.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function onCdup($socket, $params) {
280280
* @param string params
281281
*/
282282
public function onFeat($socket, $params) {
283-
$this->answer($socket, 211, 'Features', array('MDTM', 'SIZE'));
283+
$this->answer($socket, 211, 'Features', ['MDTM', 'SIZE']);
284284
}
285285

286286
/**
@@ -291,7 +291,7 @@ public function onFeat($socket, $params) {
291291
* @param string params
292292
*/
293293
public function onHelp($socket, $params) {
294-
$methods= array();
294+
$methods= [];
295295
$i= 0;
296296
foreach (get_class_methods($this) as $name) {
297297
if (0 != strncmp('on', $name, 2) || strlen($name) > 6) continue;
@@ -445,7 +445,7 @@ public function onList($socket, $params) {
445445
if ($entry instanceof StorageCollection && !strstr($options, 'd')) {
446446
$elements= $entry->elements();
447447
} else {
448-
$elements= array($entry);
448+
$elements= [$entry];
449449
}
450450

451451
$before6Months= DateUtil::addMonths(Date::now(), -6)->getTime();
@@ -511,7 +511,7 @@ public function onNlst($socket, $params) {
511511
if ($entry instanceof StorageCollection && !strstr($options, 'd')) {
512512
$elements= $entry->elements();
513513
} else {
514-
$elements= array($entry);
514+
$elements= [$entry];
515515
}
516516

517517
for ($i= 0, $s= sizeof($elements); $i < $s; $i++) {
@@ -967,7 +967,7 @@ public function handleConnect($socket) {
967967
* @return var
968968
*/
969969
public function handleData($socket) {
970-
static $public= array('onhelp', 'onuser', 'onpass', 'onquit');
970+
static $public= ['onhelp', 'onuser', 'onpass', 'onquit'];
971971

972972
$data= $socket->readLine();
973973
$this->cat && $this->cat->debug('>>> ', addcslashes($data, "\0..\17"));

0 commit comments

Comments
 (0)