Skip to content

Commit ccbc049

Browse files
committed
Merge pull request #6 from xp-framework/refactor/short-arrays
Use short array syntax
2 parents 3a01e21 + 36e3db3 commit ccbc049

File tree

110 files changed

+933
-900
lines changed

Some content is hidden

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

110 files changed

+933
-900
lines changed

src/main/php/rdbms/ConnectionManager.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class ConnectionManager extends \lang\Object implements Configurable {
1212
protected static $instance= null;
13-
public $pool= array();
13+
public $pool= [];
1414

1515
static function __static() {
1616
self::$instance= new self();
@@ -132,7 +132,7 @@ public function get($host, $user) {
132132
* @throws rdbms.ConnectionNotRegisteredException in case there's no connection for these names
133133
*/
134134
public function getByHost($hostName, $num= -1) {
135-
$results= array();
135+
$results= [];
136136
foreach ($this->pool as $id => $value) {
137137
list ($user, $host)= explode('@', $id);
138138
if ($hostName == $host) $results[]= $this->conn($id, $value);

src/main/php/rdbms/Criteria.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717
class Criteria extends \lang\Object implements SQLExpression {
1818
public
19-
$conditions = array(),
20-
$orderings = array(),
21-
$groupings = array(),
19+
$conditions = [],
20+
$orderings = [],
21+
$groupings = [],
2222
$projection = null,
23-
$fetchmode = array();
23+
$fetchmode = [];
2424

2525
static function __static() {
2626
SimpleExpression::initialize(); // Defines global constants
@@ -105,7 +105,7 @@ public function add($criterion, $value= null, $comparison= EQUAL) {
105105
* @return rdbms.Criteria this object
106106
*/
107107
public function addOrderBy($column, $order= ASCENDING) {
108-
$this->orderings[]= array($column, $order);
108+
$this->orderings[]= [$column, $order];
109109
return $this;
110110
}
111111

src/main/php/rdbms/DBConnection.class.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct($dsn) {
3636
$this->setTimeout($dsn->getProperty('timeout', 0)); // 0 means no timeout
3737

3838
// Keep this for BC reasons
39-
$observers= $dsn->getProperty('observer', array());
39+
$observers= $dsn->getProperty('observer', []);
4040
if (null !== ($cat= $dsn->getProperty('log'))) {
4141
$observers['util.log.LogObserver']= $cat;
4242
}
@@ -47,7 +47,7 @@ public function __construct($dsn) {
4747

4848
// Check if class implements BoundLogObserver: in that case use factory method to acquire instance
4949
if (\lang\XPClass::forName('util.log.BoundLogObserver')->isAssignableFrom($class)) {
50-
$this->addObserver($class->getMethod('instanceFor')->invoke(null, array($param)));
50+
$this->addObserver($class->getMethod('instanceFor')->invoke(null, [$param]));
5151

5252
// Otherwise, just use the constructor
5353
} else {
@@ -192,7 +192,7 @@ protected function affectedRows() {}
192192
public function insert() {
193193
$args= func_get_args();
194194
$args[0]= 'insert '.$args[0];
195-
call_user_func_array(array($this, 'query'), $args);
195+
call_user_func_array([$this, 'query'], $args);
196196
return $this->affectedRows();
197197
}
198198

@@ -213,7 +213,7 @@ abstract public function identity($field= null);
213213
public function update() {
214214
$args= func_get_args();
215215
$args[0]= 'update '.$args[0];
216-
call_user_func_array(array($this, 'query'), $args);
216+
call_user_func_array([$this, 'query'], $args);
217217
return $this->affectedRows();
218218
}
219219

@@ -227,7 +227,7 @@ public function update() {
227227
public function delete() {
228228
$args= func_get_args();
229229
$args[0]= 'delete '.$args[0];
230-
call_user_func_array(array($this, 'query'), $args);
230+
call_user_func_array([$this, 'query'], $args);
231231
return $this->affectedRows();
232232
}
233233

@@ -241,9 +241,9 @@ public function delete() {
241241
public function select() {
242242
$args= func_get_args();
243243
$args[0]= 'select '.$args[0];
244-
$r= call_user_func_array(array($this, 'query'), $args);
244+
$r= call_user_func_array([$this, 'query'], $args);
245245

246-
$rows= array();
246+
$rows= [];
247247
while ($row= $r->next()) $rows[]= $row;
248248
return $rows;
249249
}
@@ -257,7 +257,7 @@ public function select() {
257257
*/
258258
public function query() {
259259
$args= func_get_args();
260-
$sql= call_user_func_array(array($this, 'prepare'), $args);
260+
$sql= call_user_func_array([$this, 'prepare'], $args);
261261

262262
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::QUERY, $sql));
263263
$result= $this->query0($sql);
@@ -274,7 +274,7 @@ public function query() {
274274
*/
275275
public function open() {
276276
$args= func_get_args();
277-
$sql= call_user_func_array(array($this, 'prepare'), $args);
277+
$sql= call_user_func_array([$this, 'prepare'], $args);
278278

279279
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::QUERY, $sql));
280280
$result= $this->query0($sql, false);

src/main/php/rdbms/DBForeignKeyConstraint.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class DBForeignKeyConstraint extends DBConstraint {
1111
public
12-
$keys= array(),
12+
$keys= [],
1313
$source= '';
1414

1515
/**

src/main/php/rdbms/DBIndex.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class DBIndex extends \lang\Object {
88
public
99
$name= '',
10-
$keys= array(),
10+
$keys= [],
1111
$unique= false,
1212
$primary= false;
1313

src/main/php/rdbms/DBTable.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
class DBTable extends \lang\Object {
1010
public
1111
$name= '',
12-
$attributes= array(),
13-
$indexes= array(),
14-
$fgConstraints= array();
12+
$attributes= [],
13+
$indexes= [],
14+
$fgConstraints= [];
1515

1616
/**
1717
* Constructor

src/main/php/rdbms/DBTableAttribute.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getLength() {
137137
* @return string type
138138
*/
139139
public function getTypeString() {
140-
static $map= array(
140+
static $map= [
141141
'DB_ATTRTYPE_BINARY',
142142
'DB_ATTRTYPE_BIT',
143143
'DB_ATTRTYPE_CHAR',
@@ -168,7 +168,7 @@ public function getTypeString() {
168168
'DB_ATTRTYPE_VARCHAR',
169169
'DB_ATTRTYPE_ENUM',
170170
'DB_ATTRTYPE_DATE'
171-
);
171+
];
172172
return $map[$this->type];
173173
}
174174

src/main/php/rdbms/DSN.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
class DSN extends \lang\Object {
2525
public
2626
$url = null,
27-
$dsn = array(),
27+
$dsn = [],
2828
$flags = 0,
29-
$prop = array();
29+
$prop = [];
3030

3131
/**
3232
* Constructor

src/main/php/rdbms/DataSet.class.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@
7575
abstract class DataSet extends \lang\Object implements JoinExtractable {
7676
public
7777
$_new = true,
78-
$_changed = array();
78+
$_changed = [];
7979

8080
protected
81-
$cache= array(),
82-
$cached= array();
81+
$cache= [],
82+
$cached= [];
8383

8484
/**
8585
* Constructor. Supports the array syntax, where an associative
@@ -274,7 +274,7 @@ public function doInsert() {
274274
// in the list of changed attributes
275275
$this->{$peer->identity}= $id;
276276
}
277-
$this->_changed= array();
277+
$this->_changed= [];
278278
return $id;
279279
}
280280

@@ -287,7 +287,7 @@ public function doInsert() {
287287
*/
288288
public function doUpdate(SQLExpression $criteria) {
289289
$affected= $this->getPeer()->doUpdate($this->_changed, $criteria);
290-
$this->_changed= array();
290+
$this->_changed= [];
291291
return $affected;
292292
}
293293

@@ -300,7 +300,7 @@ public function doUpdate(SQLExpression $criteria) {
300300
*/
301301
public function doDelete(SQLExpression $criteria) {
302302
$affected= $this->getPeer()->doDelete($criteria);
303-
$this->_changed= array();
303+
$this->_changed= [];
304304
return $affected;
305305
}
306306

@@ -335,7 +335,7 @@ public function update() {
335335
$criteria->add($key, $this->{$key}, EQUAL);
336336
}
337337
$affected= $peer->doUpdate($this->_changed, $criteria);
338-
$this->_changed= array();
338+
$this->_changed= [];
339339
return $affected;
340340
}
341341

@@ -372,7 +372,7 @@ public function delete() {
372372
$criteria->add($key, $this->{$key}, EQUAL);
373373
}
374374
$affected= $peer->doDelete($criteria);
375-
$this->_changed= array();
375+
$this->_changed= [];
376376
return $affected;
377377
}
378378
}

src/main/php/rdbms/DefaultDrivers.class.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88
* @see xp://rdbms.DriverImplementationsProvider
99
*/
1010
class DefaultDrivers extends DriverImplementationsProvider {
11-
protected static $impl= array();
11+
protected static $impl= [];
1212

1313
static function __static() {
1414

1515
// MySQL support: Use mysql extension by default, mysqli otherwise. Never use mysqlnd!
1616
if (extension_loaded('mysql')) {
17-
self::$impl['mysql']= array('rdbms.mysql.MySQLConnection', 'rdbms.mysqli.MySQLiConnection', 'rdbms.mysqlx.MySqlxConnection');
17+
self::$impl['mysql']= ['rdbms.mysql.MySQLConnection', 'rdbms.mysqli.MySQLiConnection', 'rdbms.mysqlx.MySqlxConnection'];
1818
} else {
19-
self::$impl['mysql']= array('rdbms.mysqlx.MySqlxConnection', 'rdbms.mysql.MySQLConnection', 'rdbms.mysqli.MySQLiConnection');
19+
self::$impl['mysql']= ['rdbms.mysqlx.MySqlxConnection', 'rdbms.mysql.MySQLConnection', 'rdbms.mysqli.MySQLiConnection'];
2020
}
2121

2222
// Sybase support: Prefer sybase_ct over mssql
2323
if (extension_loaded('sybase_ct')) {
24-
self::$impl['sybase']= array('rdbms.sybase.SybaseConnection', 'rdbms.mssql.MsSQLConnection', 'rdbms.tds.SybasexConnection');
24+
self::$impl['sybase']= ['rdbms.sybase.SybaseConnection', 'rdbms.mssql.MsSQLConnection', 'rdbms.tds.SybasexConnection'];
2525
} else {
26-
self::$impl['sybase']= array('rdbms.mssql.MsSQLConnection', 'rdbms.sybase.SybaseConnection', 'rdbms.tds.SybasexConnection');
26+
self::$impl['sybase']= ['rdbms.mssql.MsSQLConnection', 'rdbms.sybase.SybaseConnection', 'rdbms.tds.SybasexConnection'];
2727
}
2828

2929
// MSSQL support: Prefer SQLsrv from Microsoft over mssql
3030
if (extension_loaded('sqlsrv')) {
31-
self::$impl['mssql']= array('rdbms.sqlsrv.SqlSrvConnection', 'rdbms.mssql.MsSQLConnection', 'rdbms.tds.MsSQLxConnection');
31+
self::$impl['mssql']= ['rdbms.sqlsrv.SqlSrvConnection', 'rdbms.mssql.MsSQLConnection', 'rdbms.tds.MsSQLxConnection'];
3232
} else {
33-
self::$impl['mssql']= array('rdbms.mssql.MsSQLConnection', 'rdbms.sqlsrv.SqlSrvConnection', 'rdbms.tds.MsSQLxConnection');
33+
self::$impl['mssql']= ['rdbms.mssql.MsSQLConnection', 'rdbms.sqlsrv.SqlSrvConnection', 'rdbms.tds.MsSQLxConnection'];
3434
}
3535

3636
// PostgreSQL support
37-
self::$impl['pgsql']= array('rdbms.pgsql.PostgreSQLConnection');
37+
self::$impl['pgsql']= ['rdbms.pgsql.PostgreSQLConnection'];
3838

3939
// SQLite support
40-
self::$impl['sqlite']= array('rdbms.sqlite3.SQLite3Connection', 'rdbms.sqlite.SQLiteConnection');
40+
self::$impl['sqlite']= ['rdbms.sqlite3.SQLite3Connection', 'rdbms.sqlite.SQLiteConnection'];
4141

4242
// Interbase support
43-
self::$impl['ibase']= array('rdbms.ibase.InterBaseConnection');
43+
self::$impl['ibase']= ['rdbms.ibase.InterBaseConnection'];
4444
}
4545

4646
/**

src/main/php/rdbms/DriverImplementationsProvider.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(self $parent= null) {
2424
* @return string[] implementations
2525
*/
2626
public function implementationsFor($driver) {
27-
return null === $this->parent ? array() : $this->parent->implementationsFor($driver);
27+
return null === $this->parent ? [] : $this->parent->implementationsFor($driver);
2828
}
2929

3030
/**

src/main/php/rdbms/DriverManager.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
*/
6868
class DriverManager extends \lang\Object {
6969
protected static $instance= null;
70-
public $drivers= array();
71-
protected $lookup= array();
70+
public $drivers= [];
71+
protected $lookup= [];
7272
protected $provider= null;
7373

7474
static function __static() {
@@ -114,7 +114,7 @@ public static function register($name, \lang\XPClass $class) {
114114
));
115115
}
116116
self::$instance->drivers[$name]= $class;
117-
self::$instance->lookup= array();
117+
self::$instance->lookup= [];
118118
}
119119

120120
/**
@@ -124,7 +124,7 @@ public static function register($name, \lang\XPClass $class) {
124124
*/
125125
public static function remove($name) {
126126
unset(self::$instance->drivers[$name]);
127-
self::$instance->lookup= array();
127+
self::$instance->lookup= [];
128128
}
129129

130130
/**

src/main/php/rdbms/Peer.class.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
*/
1717
class Peer extends \lang\Object {
1818
protected static
19-
$instance = array();
19+
$instance = [];
2020

2121
public
2222
$identifier = '',
2323
$table = '',
2424
$connection = '',
2525
$sequence = null,
2626
$identity = null,
27-
$primary = array(),
28-
$types = array(),
29-
$relations = array();
27+
$primary = [],
28+
$types = [],
29+
$relations = [];
3030

3131
protected
3232
$conn = null;
@@ -237,7 +237,7 @@ public function getRelatedPeer(array $path) {
237237
* @throws rdbms.SQLException in case an error occurs
238238
*/
239239
public function doSelect(SQLExpression $criteria, $max= 0) {
240-
$r= array();
240+
$r= [];
241241
for ($i= 1, $it= $this->iteratorFor($criteria, false); $it->hasNext() && (!$max || $i <= $max); $i++) {
242242
$r[]= $it->next();
243243
}
@@ -284,7 +284,7 @@ public function objectFor($record) {
284284
* @param array record optional
285285
* @return rdbms.DataSet
286286
*/
287-
public function newObject($record= array()) {
287+
public function newObject($record= []) {
288288
return new $this->identifier($record);
289289
}
290290

@@ -294,7 +294,7 @@ public function newObject($record= array()) {
294294
* @param array record optional
295295
* @return rdbms.Record
296296
*/
297-
public function newRecord($record= array()) {
297+
public function newRecord($record= []) {
298298
return new Record($record);
299299
}
300300

src/main/php/rdbms/ProfilingObserver.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ProfilingObserver extends \lang\Object implements Observer, Traceable {
2222
private $timer = null;
2323
private $lastq = null;
2424
private $dsn = null;
25-
private $timing = array();
25+
private $timing = [];
2626

2727
/**
2828
* Creates a new log observer with a given log category.
@@ -54,7 +54,7 @@ public function typeOf($sql) {
5454
$sql= strtolower(ltrim($sql));
5555
$verb= substr($sql, 0, strpos($sql, ' '));
5656

57-
if (in_array($verb, array('update', 'insert', 'select', 'delete', 'set', 'show'))) {
57+
if (in_array($verb, ['update', 'insert', 'select', 'delete', 'set', 'show'])) {
5858
return $verb;
5959
}
6060

0 commit comments

Comments
 (0)