Skip to content

Commit

Permalink
Separate chain calls (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankaest committed May 22, 2022
1 parent dda59e3 commit 54f3dbf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Filter/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ public static function getOperator(): string

public function withBoth(): self
{
return $this->withStart()->withEnd();
return $this
->withStart()
->withEnd();
}

public function withoutBoth(): self
{
return $this->withoutStart()->withoutEnd();
return $this
->withoutStart()
->withoutEnd();
}

public function withStart(): self
Expand Down
9 changes: 7 additions & 2 deletions src/QueryDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public function getSort(): ?Sort
public function read(): array
{
if ($this->data === null) {
$this->data = $this->prepareQuery()->all();
$this->data = $this
->prepareQuery()
->all();
}

return $this->data;
Expand All @@ -226,6 +228,9 @@ public function read(): array
*/
public function readOne()
{
return $this->withLimit(1)->prepareQuery()->one();
return $this
->withLimit(1)
->prepareQuery()
->one();
}
}
8 changes: 6 additions & 2 deletions tests/DataReaderFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public function testLikeFilter()
$like = new FilterLike('foo', 'bar');
$endLike = (new FilterLike('foo', 'bar'))->withoutStart();
$startLike = (new FilterLike('foo', 'bar'))->withoutEnd();
$equalLike = (new FilterLike('foo', 'bar'))->withoutEnd()->withoutStart();
$equalLike = (new FilterLike('foo', 'bar'))
->withoutEnd()
->withoutStart();

$this->assertSame([FilterLike::getOperator(), 'foo', 'bar'], $like->toArray());
$this->assertSame([FilterLike::getOperator(), 'foo', 'bar%', false], $endLike->toArray());
Expand All @@ -160,7 +162,9 @@ public function testLikeFilter()
$like = new FilterILike('foo', 'bar');
$endLike = (new FilterILike('foo', 'bar'))->withoutStart();
$startLike = (new FilterILike('foo', 'bar'))->withoutEnd();
$equalLike = (new FilterILike('foo', 'bar'))->withoutEnd()->withoutStart();
$equalLike = (new FilterILike('foo', 'bar'))
->withoutEnd()
->withoutStart();

$this->assertSame([FilterILike::getOperator(), 'foo', 'bar'], $like->toArray());
$this->assertSame([FilterILike::getOperator(), 'foo', 'bar%', false], $endLike->toArray());
Expand Down

0 comments on commit 54f3dbf

Please sign in to comment.