Skip to content

Commit

Permalink
Improve code consistency based on documentation and interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 9, 2020
1 parent 6f45767 commit 2c02bf3
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ public function it_can_combine(): void
->beConstructedThrough('with', [range('A', 'E')]);

$this
->combine(range('e', 'a'))
->combine(...range('e', 'a'))
->shouldIterateAs(['e' => 'A', 'd' => 'B', 'c' => 'C', 'b' => 'D', 'a' => 'E']);

$this
->combine(range(1, 100))
->combine(...range(1, 100))
->shouldThrow(Exception::class)
->during('all');
}
Expand Down
10 changes: 5 additions & 5 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ public function collapse(): BaseInterface
*
* @return \loophp\collection\Contract\Collection
*/
public function combinate(?int $size = null): BaseInterface
public function combinate(?int $length = null): BaseInterface
{
return $this->run(new Combinate($size));
return $this->run(new Combinate($length));
}

/**
* {@inheritdoc}
*
* @return \loophp\collection\Contract\Collection
*/
public function combine($keys): BaseInterface
public function combine(...$keys): BaseInterface
{
return $this->run(new Combine($keys));
}
Expand Down Expand Up @@ -182,9 +182,9 @@ public static function empty(): CollectionInterface
*
* @return \loophp\collection\Contract\Collection
*/
public function explode(string ...$strings): BaseInterface
public function explode(...$explodes): BaseInterface
{
return $this->run(new Explode(...$strings));
return $this->run(new Explode(...$explodes));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/Applyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace loophp\collection\Contract;

/**
* Interface Appendable.
* Interface Applyable.
*/
interface Applyable
{
/**
* Apply a callback to all the element of an array.
* Execute a callback for each element of the collection.
*
* @param callable ...$callables
*
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Collapseable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface Collapseable
{
/**
* Collapse the collection of items into a single array.
* Collapse a collection of items into a simple flat collection.
*
* @return \loophp\collection\Contract\Collection<mixed>
*/
Expand Down
7 changes: 4 additions & 3 deletions src/Contract/Combinateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
interface Combinateable
{
/**
* TODO: Combinations.
* Get all the combinations of a given length of a collection of items.
*
* @param int $size
* @param int $length
* The length.
*
* @return \loophp\collection\Contract\Collection<mixed>
*/
public function combinate(?int $size = null): Base;
public function combinate(?int $length = null): Base;
}
6 changes: 4 additions & 2 deletions src/Contract/Combineable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
interface Combineable
{
/**
* @param mixed $keys
* Combine a collection of items with some other keys.
*
* @param mixed ...$keys
*
* @return \loophp\collection\Contract\Collection<mixed>
*/
public function combine($keys): Base;
public function combine(...$keys): Base;
}
2 changes: 2 additions & 0 deletions src/Contract/Distinctable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
interface Distinctable
{
/**
* Remove duplicated values from a collection.
*
* @return \loophp\collection\Contract\Base<mixed>
*/
public function distinct(): Base;
Expand Down
6 changes: 4 additions & 2 deletions src/Contract/Explodeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
interface Explodeable
{
/**
* @param string ...$explodes
* Explode a collection into subsets based on a given value.
*
* @param mixed ...$explodes
*
* @return \loophp\collection\Contract\Collection<mixed>
*/
public function explode(string ...$explodes): Base;
public function explode(...$explodes): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface Filterable
{
/**
* Run a filter over each of the items.
* Filter collection items based on one or more callbacks.
*
* @param callable ...$callbacks
*
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Combinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Combinate implements Operation
private $length;

/**
* Permutations constructor.
* Combinate constructor.
*
* @param int $length
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Explode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
final class Explode implements Operation
{
/**
* @var string[]
* @var array<mixed>
*/
private $explodes;

/**
* Explode constructor.
*
* @param string ...$explodes
* @param mixed ...$explodes
*/
public function __construct(string ...$explodes)
public function __construct(...$explodes)
{
$this->explodes = $explodes;
}
Expand Down

0 comments on commit 2c02bf3

Please sign in to comment.