Skip to content

Commit 9da1d80

Browse files
Added validation for group sorting list
1 parent 2e41ca0 commit 9da1d80

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/Services/Order.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function fillCustom(array $groups): array
4040
protected function fillDefault(array $groups): array
4141
{
4242
foreach ($this->groups() as $group) {
43-
if (! in_array($group, $groups)) {
43+
if (! in_array($group, $groups, true)) {
4444
$groups[] = $group;
4545
}
4646
}
@@ -54,7 +54,7 @@ protected function existGroup(int $value): bool
5454
}
5555

5656
/**
57-
* @return array<Group>
57+
* @return Group[]
5858
*/
5959
protected function groups(): array
6060
{

src/SizeSorter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use DragonCode\SizeSorter\Enum\Group;
88
use DragonCode\SizeSorter\Services\MainLogic;
99
use DragonCode\SizeSorter\Services\Order;
10-
use Illuminate\Support\Collection;
10+
use DragonCode\SizeSorter\Support\Validator;
1111

1212
class SizeSorter
1313
{
@@ -22,7 +22,7 @@ public static function items(iterable $items): static
2222

2323
public function __construct(
2424
protected readonly iterable $items,
25-
protected readonly Order $order = new Order
25+
protected readonly Order $order = new Order()
2626
) {}
2727

2828
public function column(string $name): static
@@ -34,11 +34,12 @@ public function column(string $name): static
3434

3535
/**
3636
* @param Group[]|null $order
37+
*
3738
* @return $this
3839
*/
3940
public function orderBy(?array $order): static
4041
{
41-
(new Collection($order))->ensure(Group::class);
42+
Validator::ensure($order, Group::class);
4243

4344
$this->orderBy = $this->order->resolve($order);
4445

src/Support/Validator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\SizeSorter\Support;
6+
7+
use Illuminate\Support\Collection;
8+
9+
class Validator
10+
{
11+
public static function ensure(?iterable $items, string $class): void
12+
{
13+
(new Collection($items))->ensure($class);
14+
}
15+
}

0 commit comments

Comments
 (0)