Skip to content

Commit

Permalink
add Counter
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 21, 2024
1 parent 7b182f7 commit d6e5ebc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Counter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace ArrayLookup;

use Traversable;

use function count;
use function is_array;
use function iterator_count;

class Counter
{
/**
* @param array<int|string, mixed>|Traversable<int|string, mixed> $data
*/
public static function count(iterable $data): int
{
// php 8.1 compat
if (is_array($data)) {
return count($data);
}

return iterator_count($data);
}
}

0 comments on commit d6e5ebc

Please sign in to comment.