From 57f9aa31ac2258bbe3645fee048b9eb17f2da6f9 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 18 Oct 2018 17:18:23 -0400 Subject: [PATCH] address feedback --- Bigtable/src/DataClient.php | 23 ++++++++++------------- Bigtable/tests/Snippet/DataClientTest.php | 13 ++----------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index b8c1610f6e77..4522ad465200 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -413,13 +413,13 @@ private function convertToArray(Row $row) * Example: * ``` * $rowKeyStream = $dataClient->sampleRowKeys(); - * $rowKeys = iterator_to_array($rowKeyStream); - * - * print_r($rowKeys); + * foreach ($rowKeyStream as $rowKey) { + * print_r($rowKey) . PHP_EOL; + * } * ``` * * @param array $options [optional] Configuration options. - * @return \Generator + * @return \Generator A list of associative arrays, each with the keys `rowKey` and `offset`. * @throws ApiException if the remote call fails or operation fails */ public function sampleRowKeys(array $options = []) @@ -429,14 +429,11 @@ public function sampleRowKeys(array $options = []) $options + $this->options ); - $callable = (function () use ($stream) { - foreach ($stream->readAll() as $response) { - yield [ - 'rowKey' => $response->getRowKey(), - 'offset' => $response->getOffsetBytes() - ]; - }; - }); - return $callable(); + foreach ($stream->readAll() as $response) { + yield [ + 'rowKey' => $response->getRowKey(), + 'offset' => $response->getOffsetBytes() + ]; + } } } diff --git a/Bigtable/tests/Snippet/DataClientTest.php b/Bigtable/tests/Snippet/DataClientTest.php index 3c2dd51ec528..67ddc93045b9 100644 --- a/Bigtable/tests/Snippet/DataClientTest.php +++ b/Bigtable/tests/Snippet/DataClientTest.php @@ -356,9 +356,6 @@ public function testSampleRowKeys() $sampleRowKeyResponses[] = (new SampleRowKeysResponse) ->setRowKey('rk1') ->setOffsetBytes(1); - $sampleRowKeyResponses[] = (new SampleRowKeysResponse) - ->setRowKey('rk2') - ->setOffsetBytes(2); $this->serverStream->readAll() ->shouldBeCalled() @@ -374,14 +371,8 @@ public function testSampleRowKeys() $snippet->addLocal('dataClient', $this->dataClient); $res = $snippet->invoke('rowKeys'); $expectedRowKeys = [ - [ - 'rowKey' => 'rk1', - 'offset' => 1 - ], - [ - 'rowKey' => 'rk2', - 'offset' => 2 - ] + 'rowKey' => 'rk1', + 'offset' => 1 ]; $this->assertEquals( print_r($expectedRowKeys, true),