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

Parameters' getLimit returns integer or null #72

Merged
merged 1 commit into from
Dec 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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