Skip to content
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
8 changes: 3 additions & 5 deletions src/Reader/EntityReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use InvalidArgumentException;
use Yiisoft\Data\Cycle\Exception\NotSupportedFilterException;
use Yiisoft\Data\Cycle\Reader\FilterHandler\LikeHandler\LikeHandlerFactory;
use Yiisoft\Data\Cycle\Reader\QueryBuilderFilterHandler;
use Yiisoft\Data\Reader\DataReaderInterface;
use Yiisoft\Data\Reader\Filter\All;
use Yiisoft\Data\Reader\Iterable\Context;
Expand Down Expand Up @@ -57,9 +56,9 @@ final class EntityReader implements DataReaderInterface
private CachedCount $countCache;
private CachedCollection $itemsCache;
private CachedCollection $oneItemCache;

private array $filterHandlers;

/**
* @param Select|SelectQuery $query
* @param ValueReaderInterface $valueReader
Expand All @@ -69,8 +68,7 @@ public function __construct(
Select|SelectQuery $query,
ValueReaderInterface $valueReader = new FlatValueReader(),
array $extraFilterHandlers = [],
)
{
) {
$this->query = clone $query;
$this->countCache = new CachedCount($this->query);
$this->itemsCache = new CachedCollection();
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/AllHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a
{
return [];
}

#[\Override]
public function match(object|array $item, FilterInterface $filter, Context $context): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/AndXHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static function (QueryBuilder $select) use ($filter, $handlers) {
},
];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/FilterHandler/BetweenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, 'between', $filter->minValue, $filter->maxValue];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
/**
* @var Between $filter
* @var int|string|float|null $value
* @var float|int|string|null $value
*/
$value = $context->readValue($item, $filter->field);
$min = $filter->minValue;
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/FilterHandler/EqualsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, '=', $filter->value];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
/**
* @var Equals $filter
* @var int|string|float|null $itemValue
* @var float|int|string|null $itemValue
*/

$itemValue = $context->readValue($item, $filter->field);
Expand Down
6 changes: 3 additions & 3 deletions src/Reader/FilterHandler/EqualsNullHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, '=', null];
}

#[\Override]
public function match(object|array $item, FilterInterface $filter, Context $context): bool
{
/**
/**
* @var EqualsNull $filter
* @var int|string|float|null $context->readValue($item, $filter->field)
* @var float|int|string|null $context->readValue($item, $filter->field)
*/

return $context->readValue($item, $filter->field) === null;
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/FilterHandler/GreaterThanHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, '>', $filter->value];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
/**
* @var GreaterThan $filter
* @var int|string|float|null $itemValue
* @var float|int|string|null $itemValue
*/

$itemValue = $context->readValue($item, $filter->field);
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/FilterHandler/GreaterThanOrEqualHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, '>=', $filter->value];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
/**
* @var GreaterThanOrEqual $filter
* @var int|string|float|null $itemValue
* @var float|int|string|null $itemValue
*/
$itemValue = $context->readValue($item, $filter->field);
$argumentValue = $filter->value;
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/InHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, 'in', new Parameter($filter->values)];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
Expand Down
9 changes: 4 additions & 5 deletions src/Reader/FilterHandler/LessThanHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, '<', $filter->value];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
{
/**
* @var LessThan $filter
* @var int|string|float|null $itemValue
* @var float|int|string|null $itemValue
*/

$itemValue = $context->readValue($item, $filter->field);
$argumentValue = $filter->value;

Expand All @@ -44,4 +44,3 @@ public function match(array|object $item, FilterInterface $filter, Context $cont
return $itemValue < $argumentValue;
}
}

12 changes: 6 additions & 6 deletions src/Reader/FilterHandler/LessThanOrEqualHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

return [$filter->field, '<=', $filter->value];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
/**
* @var LessThanOrEqual $filter
* @var int|string|float|null $itemValue
*/
/**
* @var LessThanOrEqual $filter
* @var float|int|string|null $itemValue
*/

$itemValue = $context->readValue($item, $filter->field);
$argumentValue = $filter->value;
Expand All @@ -41,6 +41,6 @@ public function match(array|object $item, FilterInterface $filter, Context $cont
return false;
}

return $itemValue <= $argumentValue;
return $itemValue <= $argumentValue;
}
}
6 changes: 3 additions & 3 deletions src/Reader/FilterHandler/LikeHandler/BaseLikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function prepareValue(string|\Stringable $value, LikeMode $mode = Like
LikeMode::EndsWith => '%' . $escapedValue,
};
}

#[\Override]
public function match(object|array $item, FilterInterface $filter, Context $context): bool
{
Expand All @@ -54,7 +54,7 @@ public function match(object|array $item, FilterInterface $filter, Context $cont
if ($searchValue === '') {
return true;
}

/**
* @var string $searchValue
*/
Expand Down Expand Up @@ -87,4 +87,4 @@ private function matchEndsWith(string $value, string $search, ?bool $caseSensiti

return mb_strtolower(mb_substr($value, -mb_strlen($search))) === mb_strtolower($search);
}
}
}
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/LikeHandler/MysqlLikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a
{
/**
* @var Like $filter
* @var string $filter->value
* @var string $filter->value
*/
$pattern = $this->prepareValue($filter->value, $filter->mode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a
{
/**
* @var Like $filter
* @var string $filter->value
* @var string $filter->value
*/
$pattern = $this->prepareValue($filter->value, $filter->mode);

Expand Down
6 changes: 3 additions & 3 deletions src/Reader/FilterHandler/LikeHandler/SqlServerLikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function __construct()
#[\Override]
public function getAsWhereArguments(FilterInterface $filter, array $handlers): array
{
/**
* @var Like $filter
* @var string $filter->value
/**
* @var Like $filter
* @var string $filter->value
*/
$pattern = $this->prepareValue($filter->value, $filter->mode);

Expand Down
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/LikeHandler/SqliteLikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a
// The above escaping replacements will be used to build the pattern
// in the event of escape characters (% or _) being found in the $filter->value
// Sqlite does not have the ESCAPE command available

/** @var string $filter->value */
$pattern = $this->prepareValue($filter->value, $filter->mode);

Expand Down
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/NoneHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a
{
return [new Expression('1 = 0')];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/FilterHandler/NotHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a

$convertedFilter = $this->convertFilter($filter->filter);
$handledFilter = $convertedFilter instanceof Not ? $convertedFilter->filter : $convertedFilter;

/** @var QueryBuilderFilterHandler|null $handler */
$handler = $handlers[$handledFilter::class] ?? null;
if ($handler === null) {
Expand Down Expand Up @@ -105,7 +105,7 @@ private function convertNot(Not $filter, int $notCount): FilterInterface

return $notCount % 2 === 1 ? new Not($filter->filter) : $filter->filter;
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/FilterHandler/OrXHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static function (QueryBuilder $select) use ($filter, $handlers) {
},
];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/Base/Reader/BaseEntityReaderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Cycle\Database\Query\SelectQuery;
use Cycle\ORM\Select;
use Cycle\Database\Exception\StatementException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Yiisoft\Data\Cycle\Exception\NotSupportedFilterException;
Expand All @@ -16,10 +15,8 @@
use Yiisoft\Data\Cycle\Tests\Feature\DataTrait;
use Yiisoft\Data\Cycle\Tests\Support\NotSupportedFilter;
use Yiisoft\Data\Cycle\Tests\Support\StubFilter;
use Yiisoft\Data\Cycle\Tests\Support\StubFilterHandler;
use Yiisoft\Data\Reader\Filter\Equals;
use Yiisoft\Data\Reader\Iterable\ValueReader\FlatValueReader;
use Yiisoft\Data\Reader\Iterable\ValueReader\ValueReaderInterface;
use Yiisoft\Data\Reader\Sort;
use Yiisoft\Data\Tests\Common\FixtureTrait;

Expand Down
2 changes: 1 addition & 1 deletion tests/Support/StubFilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getAsWhereArguments(FilterInterface $filter, array $handlers): a
/** @var StubFilter $filter */
return ['field', 'symbol', 'value'];
}

#[\Override]
public function match(array|object $item, FilterInterface $filter, Context $context): bool
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Reader/EntityReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testNormalizeSortingCriteria(): void
// Test the functionality through a public method that uses normalizeSortingCriteria internally
$select = $this->createMock(SelectQuery::class);
$select->expects($this->once())->method('orderBy')->with(['email' => 'ASC'])->willReturnSelf();

$reader = new EntityReader($select);
$reader->withSort(Sort::only(['email'])->withOrderString('+email'))->getSql();
}
Expand Down
Loading