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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
},
"require-dev": {
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.9",
"phpunit/phpunit": "^10.5.46",
"rector/rector": "^2.0.15",
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1 || ^6.9.1"
"vimeo/psalm": "^5.26.1 || ^6.10.3"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions src/Reader/Filter/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use InvalidArgumentException;
use Yiisoft\Data\Reader\FilterInterface;

use function is_scalar;
use function sprintf;

/**
* `In` filter defines a criteria for ensuring field value matches one of the value provided.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/Reader/Iterable/FilterHandler/AllHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Yiisoft\Data\Reader\FilterInterface;
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;

use function sprintf;

/**
* `All` iterable filter handler allows combining multiple sub-filters.
* The filter matches only if all the sub-filters match.
Expand All @@ -27,7 +29,9 @@ public function match(object|array $item, FilterInterface $filter, array $iterab
foreach ($filter->getFilters() as $subFilter) {
$filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null;
if ($filterHandler === null) {
throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class));
throw new LogicException(
sprintf('Filter "%s" is not supported.', $subFilter::class),
);
}
if (!$filterHandler->match($item, $subFilter, $iterableFilterHandlers)) {
return false;
Expand Down
6 changes: 5 additions & 1 deletion src/Reader/Iterable/FilterHandler/AnyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Yiisoft\Data\Reader\FilterInterface;
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;

use function sprintf;

/**
* `Any` iterable filter handler allows combining multiple sub-filters.
* The filter matches if any of the sub-filters match.
Expand All @@ -27,7 +29,9 @@ public function match(object|array $item, FilterInterface $filter, array $iterab
foreach ($filter->getFilters() as $subFilter) {
$filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null;
if ($filterHandler === null) {
throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class));
throw new LogicException(
sprintf('Filter "%s" is not supported.', $subFilter::class),
);
}
if ($filterHandler->match($item, $subFilter, $iterableFilterHandlers)) {
return true;
Expand Down
4 changes: 1 addition & 3 deletions src/Reader/Iterable/IterableDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ private function sortItems(iterable $items, Sort $sort): iterable
$items,
static function (array|object $itemA, array|object $itemB) use ($criteria) {
foreach ($criteria as $key => $order) {
/** @psalm-var mixed $valueA */
$valueA = ArrayHelper::getValue($itemA, $key);
/** @psalm-var mixed $valueB */
$valueB = ArrayHelper::getValue($itemB, $key);

if ($valueB === $valueA) {
Expand Down Expand Up @@ -311,7 +309,7 @@ private function prepareFilterHandlers(array $filterHandlers): array
*/
private function iterableToArray(iterable $iterable): array
{
return $iterable instanceof Traversable ? iterator_to_array($iterable, true) : $iterable;
return $iterable instanceof Traversable ? iterator_to_array($iterable) : $iterable;
}

public function getFilter(): ?FilterInterface
Expand Down
2 changes: 1 addition & 1 deletion tests/Paginator/KeysetPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use function reset;
use function sprintf;

final class KeysetPaginatorTest extends Testcase
final class KeysetPaginatorTest extends TestCase
{
use PageTokenAssertTrait;

Expand Down
11 changes: 11 additions & 0 deletions tests/Paginator/OffsetPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
use Yiisoft\Data\Paginator\InvalidPageException;
use Yiisoft\Data\Paginator\OffsetPaginator;
use Yiisoft\Data\Paginator\PageNotFoundException;
use Yiisoft\Data\Paginator\PageToken;
Expand Down Expand Up @@ -601,6 +602,16 @@ public function testWithNulledPageToken(): void
$this->assertFalse($token->isPrevious);
}

public function testWithNegativeToken(): void
{
$paginator = new OffsetPaginator(new IterableDataReader([]));
$token = PageToken::next('-1');

$this->expectException(InvalidPageException::class);
$this->expectExceptionMessage('Current page should be at least 1.');
$paginator->withToken($token);
}

public function testLimitedDataReaderTotalItems(): void
{
$dataReader = (new IterableDataReader(self::DEFAULT_DATASET))->withLimit(3);
Expand Down
22 changes: 6 additions & 16 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use DateTimeImmutable;
use DateTimeInterface;
use ReflectionException;
use ReflectionObject;
use stdClass;
use Traversable;
Expand Down Expand Up @@ -87,28 +86,19 @@ protected function getInaccessibleProperty(object $object, string $propertyName)
$class = $class->getParentClass();
}

$property = $class->getProperty($propertyName);
$property->setAccessible(true);
$result = $property->getValue($object);
$property->setAccessible(false);

return $result;
return $class
->getProperty($propertyName)
->getValue($object);
}

/**
* Invokes an inaccessible method.
*
* @throws ReflectionException
*/
protected function invokeMethod(object $object, string $method, array $args = []): mixed
{
$reflection = new ReflectionObject($object);
$method = $reflection->getMethod($method);
$method->setAccessible(true);
$result = $method->invokeArgs($object, $args);
$method->setAccessible(false);

return $result;
return (new ReflectionObject($object))
->getMethod($method)
->invokeArgs($object, $args);
}

protected function iterableToArray(iterable $iterable): array
Expand Down
Loading