Skip to content
Permalink
Browse files

feat: Implemented `Countable` to resource and controller collections.

  • Loading branch information...
tarlepp committed Oct 12, 2019
1 parent 7a332de commit c62f0caa3bf7286763b5ab5c6a1548a56142821c
Showing with 15 additions and 2 deletions.
  1. +11 −0 src/Collection/CollectionTrait.php
  2. +2 −1 src/Resource/Collection.php
  3. +2 −1 src/Rest/ControllerCollection.php
@@ -13,6 +13,7 @@
use Traversable;
use function array_filter;
use function count;
use function iterator_count;
use function iterator_to_array;
/**
@@ -90,6 +91,16 @@ public function has(?string $className = null): bool
return $output;
}
/**
* Count elements of an object.
*
* @return int
*/
public function count(): int
{
return iterator_count($this->items);
}
/**
* @param string $className
*
@@ -11,6 +11,7 @@
use App\Collection\CollectionTrait;
use App\Rest\RestResourceInterface;
use Closure;
use Countable;
use InvalidArgumentException;
use Traversable;
use function sprintf;
@@ -26,7 +27,7 @@
* @method RestResourceInterface get(string $className)
* @method Traversable<int, RestResourceInterface> getAll(): Traversable
*/
class Collection
class Collection implements Countable
{
// Traits
use CollectionTrait;
@@ -10,6 +10,7 @@
use App\Collection\CollectionTrait;
use Closure;
use Countable;
use InvalidArgumentException;
use Traversable;
@@ -24,7 +25,7 @@
* @method ControllerInterface get(string $className)
* @method Traversable<int, ControllerInterface> getAll(): Traversable
*/
class ControllerCollection
class ControllerCollection implements Countable
{
// Traits
use CollectionTrait;

0 comments on commit c62f0ca

Please sign in to comment.
You can’t perform that action at this time.