Skip to content

Commit

Permalink
fix: update span and partition operations
Browse files Browse the repository at this point in the history
Update interfaces to match a bit more what's happening.
  • Loading branch information
drupol committed Nov 27, 2022
1 parent 747e1f8 commit 31d4b31
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
24 changes: 13 additions & 11 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace loophp\collection;

use Closure;
use Countable;
use Doctrine\Common\Collections\Criteria;
use Generator;
use JsonSerializable;
use loophp\collection\Contract\Collection as CollectionInterface;
use loophp\collection\Contract\Operation as OperationInterface;
use loophp\collection\Utils\CallbacksArrayReducer;
Expand All @@ -32,7 +34,7 @@
*
* @implements \loophp\collection\Contract\Collection<TKey, T>
*/
final class Collection implements CollectionInterface
final class Collection implements CollectionInterface, JsonSerializable, Countable
{
/**
* @var ClosureIteratorAggregate<TKey, T>
Expand Down Expand Up @@ -331,15 +333,15 @@ public function frequency(): CollectionInterface
* @param callable(mixed ...$parameters): iterable<NewTKey, NewT> $callable
* @param iterable<int, mixed> $parameters
*
* @return CollectionInterface<NewTKey, NewT>
* @return self<NewTKey, NewT>
*/
public static function fromCallable(callable $callable, iterable $parameters = []): CollectionInterface
{
return new self($callable, $parameters);
}

/**
* @return CollectionInterface<int, string>
* @return self<int, string>
*/
public static function fromFile(string $filepath): CollectionInterface
{
Expand All @@ -354,7 +356,7 @@ public static function fromFile(string $filepath): CollectionInterface
*
* @param Generator<NewTKey, NewT> $generator
*
* @return CollectionInterface<NewTKey, NewT>
* @return self<NewTKey, NewT>
*/
public static function fromGenerator(Generator $generator): CollectionInterface
{
Expand All @@ -367,7 +369,7 @@ public static function fromGenerator(Generator $generator): CollectionInterface
*
* @param iterable<NewTKey, NewT> $iterable
*
* @return CollectionInterface<NewTKey, NewT>
* @return self<NewTKey, NewT>
*/
public static function fromIterable(iterable $iterable): CollectionInterface
{
Expand All @@ -377,15 +379,15 @@ public static function fromIterable(iterable $iterable): CollectionInterface
/**
* @param resource $resource
*
* @return CollectionInterface<int, string>
* @return self<int, string>
*/
public static function fromResource($resource): CollectionInterface
{
return new self(static fn (): Generator => yield from new ResourceIteratorAggregate($resource));
}

/**
* @return CollectionInterface<int, string>
* @return self<int, string>
*/
public static function fromString(string $string, string $delimiter = ''): CollectionInterface
{
Expand Down Expand Up @@ -578,9 +580,9 @@ public function partition(callable ...$callbacks): CollectionInterface
/**
* @param iterable<TKey, T> $iterable
*
* @return CollectionInterface<TKey, T>
* @return Collection<TKey, T>
*/
static fn (iterable $iterable): CollectionInterface => Collection::fromIterable($iterable)
static fn (iterable $iterable): Collection => Collection::fromIterable($iterable)
);
}

Expand Down Expand Up @@ -720,9 +722,9 @@ public function span(callable ...$callbacks): CollectionInterface
/**
* @param iterable<TKey, T> $iterable
*
* @return CollectionInterface<TKey, T>
* @return Collection<TKey, T>
*/
static fn (iterable $iterable): CollectionInterface => Collection::fromIterable($iterable)
static fn (iterable $iterable): Collection => Collection::fromIterable($iterable)
);
}

Expand Down
4 changes: 0 additions & 4 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace loophp\collection\Contract;

use Countable;
use IteratorAggregate;
use JsonSerializable;
use Traversable;

/**
Expand Down Expand Up @@ -150,7 +148,6 @@ interface Collection extends
Operation\Compactable,
Operation\Comparable,
Operation\Containsable,
Countable,
Operation\Currentable,
Operation\Cycleable,
Operation\Diffable,
Expand Down Expand Up @@ -190,7 +187,6 @@ interface Collection extends
Operation\Intersperseable,
Operation\IsEmptyable,
IteratorAggregate,
JsonSerializable,
Operation\Keyable,
Operation\Keysable,
Operation\Lastable,
Expand Down
7 changes: 4 additions & 3 deletions src/Contract/Operation/Partitionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace loophp\collection\Contract\Operation;

use loophp\collection\Contract\Collection;
use loophp\collection\Collection;
use loophp\collection\Contract\Collection as CollectionInterface;

/**
* @template TKey
Expand All @@ -22,7 +23,7 @@ interface Partitionable
*
* @param callable(T, TKey, iterable<TKey, T>): bool ...$callbacks
*
* @return Collection<int, Collection<TKey, T>>
* @return CollectionInterface<int, Collection<TKey, T>>
*/
public function partition(callable ...$callbacks): Collection;
public function partition(callable ...$callbacks): CollectionInterface;
}
7 changes: 4 additions & 3 deletions src/Contract/Operation/Spanable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace loophp\collection\Contract\Operation;

use loophp\collection\Contract\Collection;
use loophp\collection\Collection;
use loophp\collection\Contract\Collection as CollectionInterface;

/**
* @template TKey
Expand All @@ -23,7 +24,7 @@ interface Spanable
*
* @param callable(T, TKey, iterable<TKey, T>): bool ...$callbacks
*
* @return Collection<int, Collection<TKey, T>>
* @return CollectionInterface<int, Collection<TKey, T>>
*/
public function span(callable ...$callbacks): Collection;
public function span(callable ...$callbacks): CollectionInterface;
}
4 changes: 2 additions & 2 deletions tests/static-analysis/partition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use loophp\collection\Contract\Collection as CollectionInterface;

/**
* @param CollectionInterface<int, CollectionInterface<int, int>> $collection
* @param CollectionInterface<int, Collection<int, int>> $collection
*/
function partition_checkListCollectionInt(CollectionInterface $collection): void
{
Expand All @@ -20,7 +20,7 @@ function partition_checkListInt(CollectionInterface $collection): void
{
}
/**
* @param CollectionInterface<int, CollectionInterface<string, string>> $collection
* @param CollectionInterface<int, Collection<string, string>> $collection
*/
function partition_checkMapCollectionString(CollectionInterface $collection): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/static-analysis/span.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use loophp\collection\Contract\Collection as CollectionInterface;

/**
* @param CollectionInterface<int, CollectionInterface<int, int>> $collection
* @param CollectionInterface<int, Collection<int, int>> $collection
*/
function span_checkListCollectionInt(CollectionInterface $collection): void
{
Expand All @@ -20,7 +20,7 @@ function span_checkListInt(CollectionInterface $collection): void
{
}
/**
* @param CollectionInterface<int, CollectionInterface<string, string>> $collection
* @param CollectionInterface<int, Collection<string, string>> $collection
*/
function span_checkMapCollectionString(CollectionInterface $collection): void
{
Expand Down

0 comments on commit 31d4b31

Please sign in to comment.