Skip to content

Commit

Permalink
Add return type to Closures.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 21, 2019
1 parent e50bbfd commit a2b9366
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/Operation/Append.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$items] = $this->parameters;

return Collection::with(
static function () use ($items, $collection) {
static function () use ($items, $collection): \Generator
{
foreach ($collection as $item) {
yield $item;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function run(CollectionInterface $collection): CollectionInterface
}

return Collection::with(
static function () use ($size, $collection) {
static function () use ($size, $collection): \Generator
{
$iterator = $collection->getIterator();

while ($iterator->valid()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Collapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ final class Collapse extends Operation
public function run(CollectionInterface $collection): CollectionInterface
{
return Collection::with(
static function () use ($collection) {
static function () use ($collection): \Generator
{
foreach ($collection as $item) {
if (\is_array($item) || $item instanceof CollectionInterface) {
foreach ($item as $value) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$keys] = $this->parameters;

return Collection::with(
static function () use ($keys, $collection) {
static function () use ($keys, $collection): \Generator
{
$original = $collection->getIterator();
$keysIterator = Collection::with($keys)->getIterator();

Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function run(CollectionInterface $collection): CollectionInterface
}

return Collection::with(
static function () use ($callbacks, $collection) {
static function () use ($callbacks, $collection): \Generator
{
foreach ($callbacks as $callback) {
foreach ($collection->getIterator() as $key => $value) {
if (true === (bool) $callback($value, $key)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Flatten.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
$depth = $this->parameters[0];

return Collection::with(
static function () use ($depth, $collection) {
static function () use ($depth, $collection): \Generator
{
$iterator = $collection->getIterator();

foreach ($iterator as $item) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Flip.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ final class Flip extends Operation
public function run(CollectionInterface $collection): CollectionInterface
{
return Collection::with(
static function () use ($collection) {
static function () use ($collection): \Generator
{
foreach ($collection as $key => $value) {
yield $value => $key;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Forget.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$keys] = $this->parameters;

return Collection::with(
static function () use ($keys, $collection) {
static function () use ($keys, $collection): \Generator
{
$keys = \array_flip($keys);

foreach ($collection->getIterator() as $key => $value) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ final class Keys extends Operation
public function run(CollectionInterface $collection): CollectionInterface
{
return Collection::with(
static function () use ($collection) {
static function () use ($collection): \Generator
{
foreach ($collection as $key => $value) {
yield $key;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
$limit = $this->parameters[0];

return Collection::with(
static function () use ($limit, $collection) {
static function () use ($limit, $collection): \Generator
{
$iterator = $collection->getIterator();

for (; (true === $iterator->valid()) && (0 !== $limit--); $iterator->next()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$sources] = $this->parameters;

return Collection::with(
static function () use ($sources, $collection) {
static function () use ($sources, $collection): \Generator
{
foreach ($collection as $item) {
yield $item;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Nth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$step, $offset] = $this->parameters;

return Collection::with(
static function () use ($step, $offset, $collection) {
static function () use ($step, $offset, $collection): \Generator
{
$position = 0;

foreach ($collection->getIterator() as $key => $item) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Only.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$keys] = $this->parameters;

return Collection::with(
static function () use ($keys, $collection) {
static function () use ($keys, $collection): \Generator
{
if ([] === $keys) {
yield from $collection;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Pad.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$size, $value] = $this->parameters;

return Collection::with(
static function () use ($size, $value, $collection) {
static function () use ($size, $value, $collection): \Generator
{
$y = 0;

foreach ($collection->getIterator() as $key => $item) {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Prepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$items] = $this->parameters;

return Collection::with(
static function () use ($items, $collection) {
static function () use ($items, $collection): \Generator
{
foreach ($items as $item) {
yield $item;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Skip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$counts] = $this->parameters;

return Collection::with(
static function () use ($counts, $collection) {
static function () use ($counts, $collection): \Generator
{
$iterator = $collection->getIterator();
$counts = \array_sum($counts);

Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$offset, $length] = $this->parameters;

return Collection::with(
static function () use ($offset, $length, $collection) {
static function () use ($offset, $length, $collection): \Generator
{
if (null === $length) {
yield from $collection->skip($offset);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$callback] = $this->parameters;

return Collection::with(
static function () use ($callback, $collection) {
static function () use ($callback, $collection): \Generator
{
$array = \iterator_to_array($collection->getIterator());

\uasort($array, $callback);
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Walk.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$callbacks] = $this->parameters;

return Collection::with(
static function () use ($callbacks, $collection) {
static function () use ($callbacks, $collection): \Generator
{
$callback = static function ($carry, $callback) {
return $callback($carry);
};
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function run(CollectionInterface $collection): CollectionInterface
[$iterables] = $this->parameters;

return Collection::with(
static function () use ($iterables, $collection) {
static function () use ($iterables, $collection): \Generator
{
$iterators =
Collection::empty()
->append($collection, ...$iterables)
Expand Down

0 comments on commit a2b9366

Please sign in to comment.