Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #72 from byCedric/feature/limit-returns-integer
Browse files Browse the repository at this point in the history
Parameters' `getLimit` returns integer or null
  • Loading branch information
tobyzerner committed Dec 2, 2015
2 parents d802eac + 82e8ad4 commit fd5c667
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ protected function getOffsetFromNumber($perPage)
* Get the limit.
*
* @param int|null $max
* @return string
* @return int|null
*/
public function getLimit($max = null)
{
$limit = $this->getPage('limit') ?: $this->getPage('size');
$limit = $this->getPage('limit') ?: $this->getPage('size') ?: null;

if ($max) {
if ($limit && $max) {
$limit = min($max, $limit);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/ParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public function testGetLimitParsesThePageLimit()
$this->assertEquals(100, $parameters->getLimit());
}

public function testGetLimitReturnsNullWhenNotSet()
{
$parameters = new Parameters(['page' => ['offset' => 50]]);

$this->assertNull($parameters->getLimit());
}

public function testGetFieldsReturnsAllFields()
{
$parameters = new Parameters(['fields' => ['posts' => 'title,content', 'users' => 'name']]);
Expand Down

0 comments on commit fd5c667

Please sign in to comment.