Skip to content

Commit 18c5d1a

Browse files
vjikStyleCIBot
andauthored
Cleanup + Test coverage 100% (#222)
Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent e12b236 commit 18c5d1a

File tree

8 files changed

+35
-25
lines changed

8 files changed

+35
-25
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
},
3838
"require-dev": {
3939
"maglnet/composer-require-checker": "^4.7.1",
40-
"phpunit/phpunit": "^10.5.45",
41-
"rector/rector": "^2.0.9",
40+
"phpunit/phpunit": "^10.5.46",
41+
"rector/rector": "^2.0.15",
4242
"roave/infection-static-analysis-plugin": "^1.35",
4343
"spatie/phpunit-watcher": "^1.24",
44-
"vimeo/psalm": "^5.26.1 || ^6.9.1"
44+
"vimeo/psalm": "^5.26.1 || ^6.10.3"
4545
},
4646
"autoload": {
4747
"psr-4": {

src/Reader/Filter/In.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use InvalidArgumentException;
88
use Yiisoft\Data\Reader\FilterInterface;
99

10+
use function is_scalar;
11+
use function sprintf;
12+
1013
/**
1114
* `In` filter defines a criteria for ensuring field value matches one of the value provided.
1215
*/

src/Reader/Iterable/FilterHandler/AllHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Yiisoft\Data\Reader\FilterInterface;
1010
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
1111

12+
use function sprintf;
13+
1214
/**
1315
* `All` iterable filter handler allows combining multiple sub-filters.
1416
* The filter matches only if all the sub-filters match.
@@ -27,7 +29,9 @@ public function match(object|array $item, FilterInterface $filter, array $iterab
2729
foreach ($filter->getFilters() as $subFilter) {
2830
$filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null;
2931
if ($filterHandler === null) {
30-
throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class));
32+
throw new LogicException(
33+
sprintf('Filter "%s" is not supported.', $subFilter::class),
34+
);
3135
}
3236
if (!$filterHandler->match($item, $subFilter, $iterableFilterHandlers)) {
3337
return false;

src/Reader/Iterable/FilterHandler/AnyHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Yiisoft\Data\Reader\FilterInterface;
1010
use Yiisoft\Data\Reader\Iterable\IterableFilterHandlerInterface;
1111

12+
use function sprintf;
13+
1214
/**
1315
* `Any` iterable filter handler allows combining multiple sub-filters.
1416
* The filter matches if any of the sub-filters match.
@@ -27,7 +29,9 @@ public function match(object|array $item, FilterInterface $filter, array $iterab
2729
foreach ($filter->getFilters() as $subFilter) {
2830
$filterHandler = $iterableFilterHandlers[$subFilter::class] ?? null;
2931
if ($filterHandler === null) {
30-
throw new LogicException(sprintf('Filter "%s" is not supported.', $subFilter::class));
32+
throw new LogicException(
33+
sprintf('Filter "%s" is not supported.', $subFilter::class),
34+
);
3135
}
3236
if ($filterHandler->match($item, $subFilter, $iterableFilterHandlers)) {
3337
return true;

src/Reader/Iterable/IterableDataReader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,7 @@ private function sortItems(iterable $items, Sort $sort): iterable
253253
$items,
254254
static function (array|object $itemA, array|object $itemB) use ($criteria) {
255255
foreach ($criteria as $key => $order) {
256-
/** @psalm-var mixed $valueA */
257256
$valueA = ArrayHelper::getValue($itemA, $key);
258-
/** @psalm-var mixed $valueB */
259257
$valueB = ArrayHelper::getValue($itemB, $key);
260258

261259
if ($valueB === $valueA) {
@@ -311,7 +309,7 @@ private function prepareFilterHandlers(array $filterHandlers): array
311309
*/
312310
private function iterableToArray(iterable $iterable): array
313311
{
314-
return $iterable instanceof Traversable ? iterator_to_array($iterable, true) : $iterable;
312+
return $iterable instanceof Traversable ? iterator_to_array($iterable) : $iterable;
315313
}
316314

317315
public function getFilter(): ?FilterInterface

tests/Paginator/KeysetPaginatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
use function reset;
3535
use function sprintf;
3636

37-
final class KeysetPaginatorTest extends Testcase
37+
final class KeysetPaginatorTest extends TestCase
3838
{
3939
use PageTokenAssertTrait;
4040

tests/Paginator/OffsetPaginatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use InvalidArgumentException;
88
use LogicException;
99
use PHPUnit\Framework\Attributes\DataProvider;
10+
use Yiisoft\Data\Paginator\InvalidPageException;
1011
use Yiisoft\Data\Paginator\OffsetPaginator;
1112
use Yiisoft\Data\Paginator\PageNotFoundException;
1213
use Yiisoft\Data\Paginator\PageToken;
@@ -601,6 +602,16 @@ public function testWithNulledPageToken(): void
601602
$this->assertFalse($token->isPrevious);
602603
}
603604

605+
public function testWithNegativeToken(): void
606+
{
607+
$paginator = new OffsetPaginator(new IterableDataReader([]));
608+
$token = PageToken::next('-1');
609+
610+
$this->expectException(InvalidPageException::class);
611+
$this->expectExceptionMessage('Current page should be at least 1.');
612+
$paginator->withToken($token);
613+
}
614+
604615
public function testLimitedDataReaderTotalItems(): void
605616
{
606617
$dataReader = (new IterableDataReader(self::DEFAULT_DATASET))->withLimit(3);

tests/TestCase.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use DateTimeImmutable;
88
use DateTimeInterface;
9-
use ReflectionException;
109
use ReflectionObject;
1110
use stdClass;
1211
use Traversable;
@@ -87,28 +86,19 @@ protected function getInaccessibleProperty(object $object, string $propertyName)
8786
$class = $class->getParentClass();
8887
}
8988

90-
$property = $class->getProperty($propertyName);
91-
$property->setAccessible(true);
92-
$result = $property->getValue($object);
93-
$property->setAccessible(false);
94-
95-
return $result;
89+
return $class
90+
->getProperty($propertyName)
91+
->getValue($object);
9692
}
9793

9894
/**
9995
* Invokes an inaccessible method.
100-
*
101-
* @throws ReflectionException
10296
*/
10397
protected function invokeMethod(object $object, string $method, array $args = []): mixed
10498
{
105-
$reflection = new ReflectionObject($object);
106-
$method = $reflection->getMethod($method);
107-
$method->setAccessible(true);
108-
$result = $method->invokeArgs($object, $args);
109-
$method->setAccessible(false);
110-
111-
return $result;
99+
return (new ReflectionObject($object))
100+
->getMethod($method)
101+
->invokeArgs($object, $args);
112102
}
113103

114104
protected function iterableToArray(iterable $iterable): array

0 commit comments

Comments
 (0)