Skip to content

Commit

Permalink
feat: Implemented Countable to resource and controller collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarlepp committed Oct 12, 2019
1 parent 7a332de commit c62f0ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Collection/CollectionTrait.php
Expand Up @@ -13,6 +13,7 @@
use Traversable; use Traversable;
use function array_filter; use function array_filter;
use function count; use function count;
use function iterator_count;
use function iterator_to_array; use function iterator_to_array;


/** /**
Expand Down Expand Up @@ -90,6 +91,16 @@ public function has(?string $className = null): bool
return $output; return $output;
} }


/**
* Count elements of an object.
*
* @return int
*/
public function count(): int
{
return iterator_count($this->items);
}

/** /**
* @param string $className * @param string $className
* *
Expand Down
3 changes: 2 additions & 1 deletion src/Resource/Collection.php
Expand Up @@ -11,6 +11,7 @@
use App\Collection\CollectionTrait; use App\Collection\CollectionTrait;
use App\Rest\RestResourceInterface; use App\Rest\RestResourceInterface;
use Closure; use Closure;
use Countable;
use InvalidArgumentException; use InvalidArgumentException;
use Traversable; use Traversable;
use function sprintf; use function sprintf;
Expand All @@ -26,7 +27,7 @@
* @method RestResourceInterface get(string $className) * @method RestResourceInterface get(string $className)
* @method Traversable<int, RestResourceInterface> getAll(): Traversable * @method Traversable<int, RestResourceInterface> getAll(): Traversable
*/ */
class Collection class Collection implements Countable
{ {
// Traits // Traits
use CollectionTrait; use CollectionTrait;
Expand Down
3 changes: 2 additions & 1 deletion src/Rest/ControllerCollection.php
Expand Up @@ -10,6 +10,7 @@


use App\Collection\CollectionTrait; use App\Collection\CollectionTrait;
use Closure; use Closure;
use Countable;
use InvalidArgumentException; use InvalidArgumentException;
use Traversable; use Traversable;


Expand All @@ -24,7 +25,7 @@
* @method ControllerInterface get(string $className) * @method ControllerInterface get(string $className)
* @method Traversable<int, ControllerInterface> getAll(): Traversable * @method Traversable<int, ControllerInterface> getAll(): Traversable
*/ */
class ControllerCollection class ControllerCollection implements Countable
{ {
// Traits // Traits
use CollectionTrait; use CollectionTrait;
Expand Down

0 comments on commit c62f0ca

Please sign in to comment.