Skip to content

Commit

Permalink
Separate chain calls (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankaest committed May 22, 2022
1 parent 0c0121e commit d6a1fd0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Paginator/KeysetPaginator.php
Expand Up @@ -292,7 +292,10 @@ private function previousPageExist(ReadableDataInterface $dataReader, Sort $sort
{
$reverseFilter = $this->getReverseFilter($sort);

foreach ($dataReader->withFilter($reverseFilter)->withLimit(1)->read() as $void) {
foreach ($dataReader
->withFilter($reverseFilter)
->withLimit(1)
->read() as $void) {
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Paginator/OffsetPaginator.php
Expand Up @@ -170,7 +170,9 @@ public function read(): iterable
throw new PaginatorException('Page not found.');
}

$this->cachedReader = $this->dataReader->withLimit($this->pageSize)->withOffset($this->getOffset());
$this->cachedReader = $this->dataReader
->withLimit($this->pageSize)
->withOffset($this->getOffset());
yield from $this->cachedReader->read();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Reader/Iterable/IterableDataReader.php
Expand Up @@ -185,7 +185,10 @@ public function read(): array
*/
public function readOne()
{
return $this->withLimit(1)->getIterator()->current();
return $this
->withLimit(1)
->getIterator()
->current();
}

protected function matchFilter(array $item, array $filter): bool
Expand Down
4 changes: 3 additions & 1 deletion tests/Paginator/KeysetPaginatorTest.php
Expand Up @@ -214,7 +214,9 @@ public function testReadObjectsWithGetters(string $orderByField, string $getter)
$this->createObjectWithGetters(3, 'Codename Boris 3'),
];

$dataReader = $this->createObjectDataReader($data)->withSort($sort);
$dataReader = $this
->createObjectDataReader($data)
->withSort($sort);
$paginator = (new KeysetPaginator($dataReader))->withPageSize(2);

$this->assertSame([$data[0], $data[1]], $this->iterableToArray($paginator->read()));
Expand Down
14 changes: 12 additions & 2 deletions tests/Reader/Iterable/IterableDataReaderTest.php
Expand Up @@ -333,7 +333,12 @@ public function testIteratorIteratorAsDataSet(): void
'name',
]);
$sorting = $sorting->withOrder(['name' => 'asc']);
$this->assertSame($this->getDataSetAscSortedByName(), $reader->withSort($sorting)->read());
$this->assertSame(
$this->getDataSetAscSortedByName(),
$reader
->withSort($sorting)
->read(),
);
}

public function testGeneratorAsDataSet(): void
Expand All @@ -344,7 +349,12 @@ public function testGeneratorAsDataSet(): void
'name',
]);
$sorting = $sorting->withOrder(['name' => 'asc']);
$this->assertSame($this->getDataSetAscSortedByName(), $reader->withSort($sorting)->read());
$this->assertSame(
$this->getDataSetAscSortedByName(),
$reader
->withSort($sorting)
->read(),
);
}

public function testCustomFilter(): void
Expand Down

0 comments on commit d6a1fd0

Please sign in to comment.