php: fix inconsistent array notation

pull/3978/head
Stanley Cheung 9 years ago
parent dcd35b8ad6
commit a5fd9d1455
  1. 16
      src/php/lib/Grpc/BaseStub.php
  2. 4
      src/php/lib/Grpc/BidiStreamingCall.php
  3. 6
      src/php/lib/Grpc/ClientStreamingCall.php
  4. 2
      src/php/lib/Grpc/ServerStreamingCall.php
  5. 4
      src/php/lib/Grpc/UnaryCall.php

@ -152,7 +152,7 @@ class BaseStub {
$timeout = $metadata['timeout']; $timeout = $metadata['timeout'];
unset($metadata_copy['timeout']); unset($metadata_copy['timeout']);
} }
return array($metadata_copy, $timeout); return [$metadata_copy, $timeout];
} }
/** /**
@ -162,7 +162,7 @@ class BaseStub {
* @throw InvalidArgumentException if key contains invalid characters * @throw InvalidArgumentException if key contains invalid characters
*/ */
private function _validate_and_normalize_metadata($metadata) { private function _validate_and_normalize_metadata($metadata) {
$metadata_copy = array(); $metadata_copy = [];
foreach ($metadata as $key => $value) { foreach ($metadata as $key => $value) {
if (!preg_match('/^[A-Za-z\d_-]+$/', $key)) { if (!preg_match('/^[A-Za-z\d_-]+$/', $key)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
@ -189,8 +189,8 @@ class BaseStub {
public function _simpleRequest($method, public function _simpleRequest($method,
$argument, $argument,
callable $deserialize, callable $deserialize,
$metadata = array(), $metadata = [],
$options = array()) { $options = []) {
list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata); list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata);
$call = new UnaryCall($this->channel, $method, $deserialize, $timeout); $call = new UnaryCall($this->channel, $method, $deserialize, $timeout);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method); $jwt_aud_uri = $this->_get_jwt_aud_uri($method);
@ -217,7 +217,7 @@ class BaseStub {
*/ */
public function _clientStreamRequest($method, public function _clientStreamRequest($method,
callable $deserialize, callable $deserialize,
$metadata = array()) { $metadata = []) {
list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata); list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata);
$call = new ClientStreamingCall($this->channel, $method, $deserialize, $timeout); $call = new ClientStreamingCall($this->channel, $method, $deserialize, $timeout);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method); $jwt_aud_uri = $this->_get_jwt_aud_uri($method);
@ -244,8 +244,8 @@ class BaseStub {
public function _serverStreamRequest($method, public function _serverStreamRequest($method,
$argument, $argument,
callable $deserialize, callable $deserialize,
$metadata = array(), $metadata = [],
$options = array()) { $options = []) {
list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata); list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata);
$call = new ServerStreamingCall($this->channel, $method, $deserialize, $timeout); $call = new ServerStreamingCall($this->channel, $method, $deserialize, $timeout);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method); $jwt_aud_uri = $this->_get_jwt_aud_uri($method);
@ -269,7 +269,7 @@ class BaseStub {
*/ */
public function _bidiRequest($method, public function _bidiRequest($method,
callable $deserialize, callable $deserialize,
$metadata = array()) { $metadata = []) {
list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata); list($actual_metadata, $timeout) = $this->_extract_timeout_from_metadata($metadata);
$call = new BidiStreamingCall($this->channel, $method, $deserialize, $timeout); $call = new BidiStreamingCall($this->channel, $method, $deserialize, $timeout);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method); $jwt_aud_uri = $this->_get_jwt_aud_uri($method);

@ -42,7 +42,7 @@ class BidiStreamingCall extends AbstractCall {
* Start the call * Start the call
* @param array $metadata Metadata to send with the call, if applicable * @param array $metadata Metadata to send with the call, if applicable
*/ */
public function start($metadata = array()) { public function start($metadata = []) {
$this->call->startBatch([OP_SEND_INITIAL_METADATA => $metadata]); $this->call->startBatch([OP_SEND_INITIAL_METADATA => $metadata]);
} }
@ -69,7 +69,7 @@ class BidiStreamingCall extends AbstractCall {
* @param array $options an array of options, possible keys: * @param array $options an array of options, possible keys:
* 'flags' => a number * 'flags' => a number
*/ */
public function write($data, $options = array()) { public function write($data, $options = []) {
$message_array = ['message' => $data->serialize()]; $message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) { if (isset($options['flags'])) {
$message_array['flags'] = $options['flags']; $message_array['flags'] = $options['flags'];

@ -42,7 +42,7 @@ class ClientStreamingCall extends AbstractCall {
* Start the call. * Start the call.
* @param array $metadata Metadata to send with the call, if applicable * @param array $metadata Metadata to send with the call, if applicable
*/ */
public function start($metadata = array()) { public function start($metadata = []) {
$this->call->startBatch([OP_SEND_INITIAL_METADATA => $metadata]); $this->call->startBatch([OP_SEND_INITIAL_METADATA => $metadata]);
} }
@ -53,7 +53,7 @@ class ClientStreamingCall extends AbstractCall {
* @param array $options an array of options, possible keys: * @param array $options an array of options, possible keys:
* 'flags' => a number * 'flags' => a number
*/ */
public function write($data, $options = array()) { public function write($data, $options = []) {
$message_array = ['message' => $data->serialize()]; $message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) { if (isset($options['flags'])) {
$message_array['flags'] = $options['flags']; $message_array['flags'] = $options['flags'];
@ -72,6 +72,6 @@ class ClientStreamingCall extends AbstractCall {
OP_RECV_MESSAGE => true, OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true]); OP_RECV_STATUS_ON_CLIENT => true]);
$this->metadata = $event->metadata; $this->metadata = $event->metadata;
return array($this->deserializeResponse($event->message), $event->status); return [$this->deserializeResponse($event->message), $event->status];
} }
} }

@ -45,7 +45,7 @@ class ServerStreamingCall extends AbstractCall {
* @param array $options an array of options, possible keys: * @param array $options an array of options, possible keys:
* 'flags' => a number * 'flags' => a number
*/ */
public function start($data, $metadata = array(), $options = array()) { public function start($data, $metadata = [], $options = []) {
$message_array = ['message' => $data->serialize()]; $message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) { if (isset($options['flags'])) {
$message_array['flags'] = $options['flags']; $message_array['flags'] = $options['flags'];

@ -45,7 +45,7 @@ class UnaryCall extends AbstractCall {
* @param array $options an array of options, possible keys: * @param array $options an array of options, possible keys:
* 'flags' => a number * 'flags' => a number
*/ */
public function start($data, $metadata = array(), $options = array()) { public function start($data, $metadata = [], $options = []) {
$message_array = ['message' => $data->serialize()]; $message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) { if (isset($options['flags'])) {
$message_array['flags'] = $options['flags']; $message_array['flags'] = $options['flags'];
@ -66,6 +66,6 @@ class UnaryCall extends AbstractCall {
$event = $this->call->startBatch([ $event = $this->call->startBatch([
OP_RECV_MESSAGE => true, OP_RECV_MESSAGE => true,
OP_RECV_STATUS_ON_CLIENT => true]); OP_RECV_STATUS_ON_CLIENT => true]);
return array($this->deserializeResponse($event->message), $event->status); return [$this->deserializeResponse($event->message), $event->status];
} }
} }

Loading…
Cancel
Save