Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
Make 'numberOfRecords' null when 'completeListSize' not given.
Browse files Browse the repository at this point in the history
If the server doesn't return 'completeListSize', it's better to make
it clear that we have no clue how many records we will get.
  • Loading branch information
danmichaelo committed Jul 12, 2016
1 parent 5bc3455 commit aad064d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/Records.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class Records extends EventEmitter implements \Iterator {
private $resumptionToken;
private $initialResumptionToken;

/** @var int Total number of records in the result set */
public $numberOfRecords;
/** @var int Total number of records in the result set. Only defined if the
server returns 'completeListSize', which is optional. Even if defined, the
value may still be only an estimate. */
public $numberOfRecords = null;

private $data = array();

Expand Down Expand Up @@ -135,12 +137,11 @@ private function fetchMore()

$this->data = $this->lastResponse->records;

if (isset($this->lastResponse->numberOfRecords) && !is_null($this->lastResponse->numberOfRecords)) {
if (!is_null($this->lastResponse->numberOfRecords)) {
$this->numberOfRecords = $this->lastResponse->numberOfRecords;
$this->position = $this->lastResponse->cursor + 1;

} else if (!isset($this->numberOfRecords)) {
$this->numberOfRecords = count($this->lastResponse->records);
if (!is_null($this->lastResponse->cursor)) {
$this->position = $this->lastResponse->cursor + 1;
}
}

if (isset($this->lastResponse->resumptionToken)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/RecordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testBasicIteration()
$client = new Client($uri, null, $http);
$records = new Records($args['from'], $args['until'], $args['set'], $client);

$this->assertEquals(8, $records->numberOfRecords);
$this->assertNull($records->numberOfRecords);
$records->rewind();

$this->assertEquals(1, $records->key());
Expand Down

0 comments on commit aad064d

Please sign in to comment.