Skip to content

Commit

Permalink
Merge pull request #137 from SimonFrings/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus authored Aug 9, 2021
2 parents 3fb07dd + baf56b6 commit 648174d
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 91 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ proxy servers etc.), you can explicitly pass a custom instance of the
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'dns' => '127.0.0.1',
'tcp' => array(
'tcp' => [
'bindto' => '192.168.10.1:0'
),
'tls' => array(
],
'tls' => [
'verify_peer' => false,
'verify_peer_name' => false
)
));
]);

$factory = new React\MySQL\Factory(null, $connector);
```
Expand Down Expand Up @@ -302,7 +302,7 @@ and sending your database queries.

#### query()

The `query(string $query, array $params = array()): PromiseInterface` method can be used to
The `query(string $query, array $params = []): PromiseInterface` method can be used to
perform an async query.

This method returns a promise that will resolve with a `QueryResult` on
Expand Down Expand Up @@ -358,7 +358,7 @@ suited for exposing multiple possible results.

#### queryStream()

The `queryStream(string $sql, array $params = array()): ReadableStreamInterface` method can be used to
The `queryStream(string $sql, array $params = []): ReadableStreamInterface` method can be used to
perform an async query and stream the rows of the result set.

This method returns a readable stream that will emit each row of the
Expand Down Expand Up @@ -513,7 +513,7 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.4 through current PHP 7+ and
HHVM.
It's *highly recommended to use PHP 7+* for this project.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests

Expand Down Expand Up @@ -551,7 +551,7 @@ $ docker run -it --rm --net=host \
To run the test suite, go to the project root and run:

```bash
$ php vendor/bin/phpunit
$ vendor/bin/phpunit
```

## License
Expand Down
4 changes: 3 additions & 1 deletion examples/12-slow-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@
});

$connection->quit();
}, 'printf');
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
4 changes: 2 additions & 2 deletions src/Commands/AuthenticateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AuthenticateCommand extends AbstractCommand
* @see self::$charsetNumber
* @see \React\MySQL\Io\Query::$escapeChars
*/
private static $charsetMap = array(
private static $charsetMap = [
'latin1' => 8,
'latin2' => 9,
'ascii' => 11,
Expand All @@ -42,7 +42,7 @@ class AuthenticateCommand extends AbstractCommand
'latin7' => 41,
'utf8mb4' => 45,
'binary' => 63
);
];

/**
* @param string $user
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface ConnectionInterface extends EventEmitterInterface
* @param array $params Parameters which should be bound to query
* @return PromiseInterface Returns a Promise<QueryResult,Exception>
*/
public function query($sql, array $params = array());
public function query($sql, array $params = []);

/**
* Performs an async query and streams the rows of the result set.
Expand Down Expand Up @@ -161,7 +161,7 @@ public function query($sql, array $params = array());
* @param array $params Parameters which should be bound to query
* @return ReadableStreamInterface
*/
public function queryStream($sql, $params = array());
public function queryStream($sql, $params = []);

/**
* Checks that the connection is alive.
Expand Down
14 changes: 7 additions & 7 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class Factory
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):
*
* ```php
* $connector = new React\Socket\Connector(array(
* $connector = new React\Socket\Connector([
* 'dns' => '127.0.0.1',
* 'tcp' => array(
* 'tcp' => [
* 'bindto' => '192.168.10.1:0'
* ),
* 'tls' => array(
* ],
* 'tls' => [
* 'verify_peer' => false,
* 'verify_peer_name' => false
* )
* ));
* ]
* ]);
*
* $factory = new React\MySQL\Factory(null, $connector);
* ```
Expand All @@ -62,7 +62,7 @@ class Factory
public function __construct(LoopInterface $loop = null, ConnectorInterface $connector = null)
{
$this->loop = $loop ?: Loop::get();
$this->connector = $connector ?: new Connector(array(), $this->loop);
$this->connector = $connector ?: new Connector([], $this->loop);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Io/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(SocketConnectionInterface $stream, Executor $executo
/**
* {@inheritdoc}
*/
public function query($sql, array $params = array())
public function query($sql, array $params = [])
{
$query = new Query($sql);
if ($params) {
Expand All @@ -75,7 +75,7 @@ public function query($sql, array $params = array())
$deferred = new Deferred();

// store all result set rows until result set end
$rows = array();
$rows = [];
$command->on('result', function ($row) use (&$rows) {
$rows[] = $row;
});
Expand All @@ -85,7 +85,7 @@ public function query($sql, array $params = array())
$result->resultRows = $rows;
$result->warningCount = $command->warningCount;

$rows = array();
$rows = [];

$deferred->resolve($result);
});
Expand All @@ -106,7 +106,7 @@ public function query($sql, array $params = array())
return $deferred->promise();
}

public function queryStream($sql, $params = array())
public function queryStream($sql, $params = [])
{
$query = new Query($sql);
if ($params) {
Expand Down Expand Up @@ -162,9 +162,9 @@ public function close()
// reject all pending commands if connection is closed
while (!$this->executor->isIdle()) {
$command = $this->executor->dequeue();
$command->emit('error', array(
$command->emit('error', [
new \RuntimeException('Connection lost')
));
]);
}

$this->emit('close');
Expand Down
2 changes: 1 addition & 1 deletion src/Io/LazyConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LazyConnection extends EventEmitter implements ConnectionInterface

public function __construct(Factory $factory, $uri, LoopInterface $loop)
{
$args = array();
$args = [];
\parse_str(\parse_url($uri, \PHP_URL_QUERY), $args);
if (isset($args['idle'])) {
$this->idlePeriod = (float)$args['idle'];
Expand Down
14 changes: 7 additions & 7 deletions src/Io/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public function __construct(DuplexStreamInterface $stream, Executor $executor)

public function start()
{
$this->stream->on('data', array($this, 'parse'));
$this->stream->on('close', array($this, 'onClose'));
$this->stream->on('data', [$this, 'parse']);
$this->stream->on('close', [$this, 'onClose']);
}

public function debug($message)
Expand Down Expand Up @@ -221,7 +221,7 @@ public function parse($data)
// Empty data packet during result set => row with only empty strings
$this->debug('Result set empty row data');

$row = array();
$row = [];
foreach ($this->resultFields as $field) {
$row[$field['name']] = '';
}
Expand Down Expand Up @@ -272,7 +272,7 @@ private function onResultRow($row)
{
// $this->debug('row data: ' . json_encode($row));
$command = $this->currCommand;
$command->emit('result', array($row));
$command->emit('result', [$row]);
}

private function onError(Exception $error)
Expand All @@ -283,7 +283,7 @@ private function onError(Exception $error)
$command = $this->currCommand;
$this->currCommand = null;

$command->emit('error', array($error));
$command->emit('error', [$error]);
}
}

Expand Down Expand Up @@ -322,9 +322,9 @@ public function onClose()
if ($command instanceof QuitCommand) {
$command->emit('success');
} else {
$command->emit('error', array(
$command->emit('error', [
new \RuntimeException('Connection lost')
));
]);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Io/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Query
* @var array<string,string>
* @see \React\MySQL\Commands\AuthenticateCommand::$charsetMap
*/
private $escapeChars = array(
private $escapeChars = [
"\x00" => "\\0",
"\r" => "\\r",
"\n" => "\\n",
Expand All @@ -34,7 +34,7 @@ class Query
"\\" => "\\\\",
//"%" => "\\%",
//"_" => "\\_",
);
];

public function __construct($sql)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ protected function buildSql()

return $sql;
/*
$names = array();
$names = [];
$inName = false;
$currName = '';
$currIdx = 0;
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function buildSql()
$names[$currIdx] = $currName;
}
$namedMarks = $unnamedMarks = array();
$namedMarks = $unnamedMarks = [];
foreach ($this->params as $arg) {
if (is_array($arg)) {
$namedMarks += $arg;
Expand Down
4 changes: 2 additions & 2 deletions src/Io/QueryStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(QueryCommand $command, ConnectionInterface $connecti
}
$this->started = true;

$this->emit('data', array($row));
$this->emit('data', [$row]);
});
$command->on('end', function () {
$this->emit('end');
Expand All @@ -46,7 +46,7 @@ public function __construct(QueryCommand $command, ConnectionInterface $connecti
$this->close();
});
$command->on('error', function ($err) {
$this->emit('error', array($err));
$this->emit('error', [$err]);
$this->close();
});
}
Expand Down
8 changes: 4 additions & 4 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getConnectionOptions($debug = false)
] + ($debug ? ['debug' => true] : []);
}

protected function getConnectionString($params = array())
protected function getConnectionString($params = [])
{
$parts = $params + $this->getConnectionOptions();

Expand Down Expand Up @@ -56,23 +56,23 @@ protected function getDataTable()

protected function expectCallableOnce()
{
$mock = $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
$mock = $this->getMockBuilder('stdClass')->setMethods(['__invoke'])->getMock();
$mock->expects($this->once())->method('__invoke');

return $mock;
}

protected function expectCallableOnceWith($value)
{
$mock = $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
$mock = $this->getMockBuilder('stdClass')->setMethods(['__invoke'])->getMock();
$mock->expects($this->once())->method('__invoke')->with($value);

return $mock;
}

protected function expectCallableNever()
{
$mock = $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
$mock = $this->getMockBuilder('stdClass')->setMethods(['__invoke'])->getMock();
$mock->expects($this->never())->method('__invoke');

return $mock;
Expand Down
Loading

0 comments on commit 648174d

Please sign in to comment.