Merge pull request #7841 from fr05t1k/cs

Little bit improving code style and php docs
pull/7967/head
Stanley Cheung 9 years ago committed by GitHub
commit fca79d78e4
  1. 37
      src/php/lib/Grpc/AbstractCall.php
  2. 10
      src/php/lib/Grpc/BidiStreamingCall.php
  3. 6
      src/php/lib/Grpc/ClientStreamingCall.php
  4. 12
      src/php/lib/Grpc/ServerStreamingCall.php
  5. 4
      src/php/lib/Grpc/UnaryCall.php

@ -34,8 +34,15 @@
namespace Grpc;
/**
* Class AbstractCall
* @package Grpc
*/
abstract class AbstractCall
{
/**
* @var Call
*/
protected $call;
protected $deserialize;
protected $metadata;
@ -51,13 +58,15 @@ abstract class AbstractCall
* the response
* @param array $options Call options (optional)
*/
public function __construct(Channel $channel,
$method,
$deserialize,
$options = [])
{
if (isset($options['timeout']) &&
is_numeric($timeout = $options['timeout'])) {
public function __construct(
Channel $channel,
$method,
$deserialize,
$options = []
) {
if (array_key_exists('timeout', $options) &&
is_numeric($timeout = $options['timeout'])
) {
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
@ -68,17 +77,19 @@ abstract class AbstractCall
$this->deserialize = $deserialize;
$this->metadata = null;
$this->trailing_metadata = null;
if (isset($options['call_credentials_callback']) &&
if (array_key_exists('call_credentials_callback', $options) &&
is_callable($call_credentials_callback =
$options['call_credentials_callback'])) {
$options['call_credentials_callback'])
) {
$call_credentials = CallCredentials::createFromPlugin(
$call_credentials_callback);
$call_credentials_callback
);
$this->call->setCredentials($call_credentials);
}
}
/**
* @return The metadata sent by the server.
* @return mixed The metadata sent by the server.
*/
public function getMetadata()
{
@ -86,7 +97,7 @@ abstract class AbstractCall
}
/**
* @return The trailing metadata sent by the server.
* @return mixed The trailing metadata sent by the server.
*/
public function getTrailingMetadata()
{
@ -114,7 +125,7 @@ abstract class AbstractCall
*
* @param string $value The binary value to deserialize
*
* @return The deserialized value
* @return mixed The deserialized value
*/
protected function deserializeResponse($value)
{

@ -45,7 +45,7 @@ class BidiStreamingCall extends AbstractCall
*
* @param array $metadata Metadata to send with the call, if applicable
*/
public function start($metadata = [])
public function start(array $metadata = [])
{
$this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,
@ -55,7 +55,7 @@ class BidiStreamingCall extends AbstractCall
/**
* Reads the next value from the server.
*
* @return The next value from the server, or null if there is none
* @return mixed The next value from the server, or null if there is none
*/
public function read()
{
@ -82,7 +82,7 @@ class BidiStreamingCall extends AbstractCall
public function write($data, $options = [])
{
$message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) {
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
@ -103,8 +103,8 @@ class BidiStreamingCall extends AbstractCall
/**
* Wait for the server to send the status, and return it.
*
* @return object The status object, with integer $code, string $details,
* and array $metadata members
* @return \stdClass The status object, with integer $code, string $details,
* and array $metadata members
*/
public function getStatus()
{

@ -60,10 +60,10 @@ class ClientStreamingCall extends AbstractCall
* @param array $options an array of options, possible keys:
* 'flags' => a number
*/
public function write($data, $options = [])
public function write($data, array $options = [])
{
$message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) {
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([
@ -74,7 +74,7 @@ class ClientStreamingCall extends AbstractCall
/**
* Wait for the server to respond with data and a status.
*
* @return [response data, status]
* @return array [response data, status]
*/
public function wait()
{

@ -36,14 +36,14 @@ namespace Grpc;
/**
* Represents an active call that sends a single message and then gets a stream
* of reponses.
* of responses.
*/
class ServerStreamingCall extends AbstractCall
{
/**
* Start the call.
*
* @param $data The data to send
* @param mixed $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* @param array $options an array of options, possible keys:
* 'flags' => a number
@ -51,7 +51,7 @@ class ServerStreamingCall extends AbstractCall
public function start($data, $metadata = [], $options = [])
{
$message_array = ['message' => $data->serialize()];
if (isset($options['flags'])) {
if (array_key_exists('flags', $options)) {
$message_array['flags'] = $options['flags'];
}
$event = $this->call->startBatch([
@ -64,7 +64,7 @@ class ServerStreamingCall extends AbstractCall
}
/**
* @return An iterator of response values
* @return mixed An iterator of response values
*/
public function responses()
{
@ -82,8 +82,8 @@ class ServerStreamingCall extends AbstractCall
/**
* Wait for the server to send the status, and return it.
*
* @return object The status object, with integer $code, string $details,
* and array $metadata members
* @return \stdClass The status object, with integer $code, string $details,
* and array $metadata members
*/
public function getStatus()
{

@ -43,7 +43,7 @@ class UnaryCall extends AbstractCall
/**
* Start the call.
*
* @param $data The data to send
* @param mixed $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* @param array $options an array of options, possible keys:
* 'flags' => a number
@ -66,7 +66,7 @@ class UnaryCall extends AbstractCall
/**
* Wait for the server to respond with data and a status.
*
* @return [response data, status]
* @return array [response data, status]
*/
public function wait()
{

Loading…
Cancel
Save