Skip to content

Commit

Permalink
Fix psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jan 5, 2022
1 parent 234fcac commit d0e565b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/DataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ public function toJson($options = 0): string

public function toCollection(): Enumerable
{
return $this->isPaginated()
? new Collection($this->items)
: $this->items;
if ($this->isPaginated()) {
throw InvalidDataCollectionModification::cannotCastToCollection();
}

/** @var \Illuminate\Support\Enumerable $items */
$items = $this->items;

return $items;
}

public function getIterator(): ArrayIterator
Expand Down
9 changes: 7 additions & 2 deletions src/Exceptions/InvalidDataCollectionModification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ class InvalidDataCollectionModification extends Exception
{
public static function cannotSetItem(): self
{
return new self('Cannot set an item in a paginated collection');
return new self('Cannot set an item in a paginated or Lazy data collection');
}

public static function cannotUnSetItem(): self
{
return new self('Cannot unset an item in a paginated collection');
return new self('Cannot unset an item in a paginated or Lazy data collection');
}

public static function cannotCastToCollection()
{
return new self('Cannot cast a paginated collection into a collection');
}
}

0 comments on commit d0e565b

Please sign in to comment.