Skip to content

Commit d4ff655

Browse files
authored
Fix #28: Correct work iterable processors with non-exists fields + Fix psalm errors (#78)
1 parent f0db33e commit d4ff655

19 files changed

+284
-17
lines changed

src/Paginator/KeysetPaginator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ public function read(): iterable
124124
*
125125
* @psalm-mutation-free
126126
*/
127-
public function withPreviousPageToken(?string $value): self
127+
public function withPreviousPageToken(?string $token): self
128128
{
129129
$new = clone $this;
130-
$new->firstValue = $value;
130+
$new->firstValue = $token;
131131
$new->lastValue = null;
132132
return $new;
133133
}
@@ -137,11 +137,11 @@ public function withPreviousPageToken(?string $value): self
137137
*
138138
* @psalm-mutation-free
139139
*/
140-
public function withNextPageToken(?string $value): self
140+
public function withNextPageToken(?string $token): self
141141
{
142142
$new = clone $this;
143143
$new->firstValue = null;
144-
$new->lastValue = $value;
144+
$new->lastValue = $token;
145145
return $new;
146146
}
147147

src/Paginator/OffsetPaginator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ public function withCurrentPage(int $page): self
8484
*
8585
* @psalm-mutation-free
8686
*/
87-
public function withPageSize(int $size): self
87+
public function withPageSize(int $pageSize): self
8888
{
89-
if ($size < 1) {
89+
if ($pageSize < 1) {
9090
throw new PaginatorException('Page size should be at least 1');
9191
}
9292
$new = clone $this;
93-
$new->pageSize = $size;
93+
$new->pageSize = $pageSize;
9494
$new->cachedReader = null;
9595
return $new;
9696
}

src/Paginator/PaginatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function withPreviousPageToken(?string $token): self;
5151
*
5252
* @psalm-mutation-free
5353
*/
54-
public function withPageSize(int $limit): self;
54+
public function withPageSize(int $pageSize): self;
5555

5656
public function getPageSize(): int;
5757

src/Reader/Iterable/Processor/Equals.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
88

9+
use function array_key_exists;
10+
911
class Equals implements IterableProcessorInterface, FilterProcessorInterface
1012
{
1113
public function getOperator(): string
@@ -19,6 +21,6 @@ public function match(array $item, array $arguments, array $filterProcessors): b
1921
throw new \InvalidArgumentException('$arguments should contain exactly two elements');
2022
}
2123
[$field, $value] = $arguments;
22-
return $item[$field] == $value;
24+
return array_key_exists($field, $item) && $item[$field] == $value;
2325
}
2426
}

src/Reader/Iterable/Processor/GreaterThan.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
88

9+
use function array_key_exists;
10+
911
class GreaterThan implements IterableProcessorInterface, FilterProcessorInterface
1012
{
1113
public function getOperator(): string
@@ -19,6 +21,6 @@ public function match(array $item, array $arguments, array $filterProcessors): b
1921
throw new \InvalidArgumentException('$arguments should contain exactly two elements');
2022
}
2123
[$field, $value] = $arguments;
22-
return $item[$field] > $value;
24+
return array_key_exists($field, $item) && $item[$field] > $value;
2325
}
2426
}

src/Reader/Iterable/Processor/GreaterThanOrEqual.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
88

9+
use function array_key_exists;
10+
911
class GreaterThanOrEqual implements IterableProcessorInterface, FilterProcessorInterface
1012
{
1113
public function getOperator(): string
@@ -19,6 +21,6 @@ public function match(array $item, array $arguments, array $filterProcessors): b
1921
throw new \InvalidArgumentException('$arguments should contain exactly two elements');
2022
}
2123
[$field, $value] = $arguments;
22-
return $item[$field] >= $value;
24+
return array_key_exists($field, $item) && $item[$field] >= $value;
2325
}
2426
}

src/Reader/Iterable/Processor/GroupProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
abstract class GroupProcessor implements IterableProcessorInterface, FilterProcessorInterface
1010
{
11-
abstract protected function checkResults(array $result): bool;
11+
abstract protected function checkResults(array $results): bool;
1212

1313
abstract protected function checkResult($result): ?bool;
1414

src/Reader/Iterable/Processor/In.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
88

9+
use function array_key_exists;
10+
911
class In implements IterableProcessorInterface, FilterProcessorInterface
1012
{
1113
public function getOperator(): string
@@ -22,6 +24,6 @@ public function match(array $item, array $arguments, array $filterProcessors): b
2224
if (!is_array($values)) {
2325
throw new \InvalidArgumentException('The values not an array');
2426
}
25-
return in_array($item[$field], $values, false);
27+
return array_key_exists($field, $item) && in_array($item[$field], $values, false);
2628
}
2729
}

src/Reader/Iterable/Processor/LessThan.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
88

9+
use function array_key_exists;
10+
911
class LessThan implements IterableProcessorInterface, FilterProcessorInterface
1012
{
1113
public function getOperator(): string
@@ -19,6 +21,6 @@ public function match(array $item, array $arguments, array $filterProcessors): b
1921
throw new \InvalidArgumentException('$arguments should contain exactly two elements');
2022
}
2123
[$field, $value] = $arguments;
22-
return $item[$field] < $value;
24+
return array_key_exists($field, $item) && $item[$field] < $value;
2325
}
2426
}

src/Reader/Iterable/Processor/LessThanOrEqual.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
88

9+
use function array_key_exists;
10+
911
class LessThanOrEqual implements IterableProcessorInterface, FilterProcessorInterface
1012
{
1113
public function getOperator(): string
@@ -19,6 +21,6 @@ public function match(array $item, array $arguments, array $filterProcessors): b
1921
throw new \InvalidArgumentException('$arguments should contain exactly two elements');
2022
}
2123
[$field, $value] = $arguments;
22-
return $item[$field] <= $value;
24+
return array_key_exists($field, $item) && $item[$field] <= $value;
2325
}
2426
}

0 commit comments

Comments
 (0)