Skip to content

Commit

Permalink
Merge pull request grpc#7841 from fr05t1k/cs
Browse files Browse the repository at this point in the history
Little bit improving code style and php docs
  • Loading branch information
stanley-cheung authored Sep 1, 2016
2 parents a3328ae + d58199b commit fca79d7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
37 changes: 24 additions & 13 deletions src/php/lib/Grpc/AbstractCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@

namespace Grpc;

/**
* Class AbstractCall
* @package Grpc
*/
abstract class AbstractCall
{
/**
* @var Call
*/
protected $call;
protected $deserialize;
protected $metadata;
Expand All @@ -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);
Expand All @@ -68,25 +77,27 @@ public function __construct(Channel $channel,
$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()
{
return $this->metadata;
}

/**
* @return The trailing metadata sent by the server.
* @return mixed The trailing metadata sent by the server.
*/
public function getTrailingMetadata()
{
Expand Down Expand Up @@ -114,7 +125,7 @@ public function cancel()
*
* @param string $value The binary value to deserialize
*
* @return The deserialized value
* @return mixed The deserialized value
*/
protected function deserializeResponse($value)
{
Expand Down
10 changes: 5 additions & 5 deletions src/php/lib/Grpc/BidiStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,7 +55,7 @@ public function start($metadata = [])
/**
* 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()
{
Expand All @@ -82,7 +82,7 @@ public function read()
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([
Expand All @@ -103,8 +103,8 @@ public function writesDone()
/**
* 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()
{
Expand Down
6 changes: 3 additions & 3 deletions src/php/lib/Grpc/ClientStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public function start($metadata = [])
* @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([
Expand All @@ -74,7 +74,7 @@ public function write($data, $options = [])
/**
* Wait for the server to respond with data and a status.
*
* @return [response data, status]
* @return array [response data, status]
*/
public function wait()
{
Expand Down
12 changes: 6 additions & 6 deletions src/php/lib/Grpc/ServerStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@

/**
* 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
*/
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([
Expand All @@ -64,7 +64,7 @@ public function start($data, $metadata = [], $options = [])
}

/**
* @return An iterator of response values
* @return mixed An iterator of response values
*/
public function responses()
{
Expand All @@ -82,8 +82,8 @@ public function responses()
/**
* 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()
{
Expand Down
4 changes: 2 additions & 2 deletions src/php/lib/Grpc/UnaryCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -66,7 +66,7 @@ public function start($data, $metadata = [], $options = [])
/**
* Wait for the server to respond with data and a status.
*
* @return [response data, status]
* @return array [response data, status]
*/
public function wait()
{
Expand Down

0 comments on commit fca79d7

Please sign in to comment.