Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move static factory fill method #49

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Cocur\Chain\Link\Count;
use Cocur\Chain\Link\CountValues;
use Cocur\Chain\Link\Diff;
use Cocur\Chain\Link\Fill;
use Cocur\Chain\Link\Filter;
use Cocur\Chain\Link\First;
use Cocur\Chain\Link\Find;
Expand Down Expand Up @@ -56,7 +55,6 @@ class Chain extends AbstractChain implements Countable
use Count;
use CountValues;
use Diff;
use Fill;
use Filter;
use Find;
use First;
Expand Down Expand Up @@ -136,4 +134,22 @@ public static function createFromString(string $delimiter, string $string, array

return $chain;
}

/**
* Create a new Chain and fill with values.
*
* Creates a new Chain and fills the array with `num` entries of the value of `value` parameters, keys starting
* at the `startIndex` parameter.
*
* @param int $startIndex The first index of the array. If `startIndex` is negative, the first index of the
* returned array will be `startIndex` and the following indices will start from zero.
* @param int $num Number of elements to insert. Must be greater than or equal to zero.
* @param mixed $value value to use for filling
*
* @return self
*/
public static function fill(int $startIndex, int $num, $value = null): self
{
return new self(array_fill($startIndex, $num, $value));
}
}
30 changes: 0 additions & 30 deletions src/Link/Fill.php

This file was deleted.

13 changes: 12 additions & 1 deletion tests/ChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public function createCreatesChainBySplittingThrowsOnInvalidPattern(): void
Chain::createFromString(',', '1,2,3', ['regexp' => true]);
}

/**
* @test
* @covers \Cocur\Chain\Chain::fill()
*/
public function fillCreatesAFilledChain(): void
{
$chain = Chain::fill(0, 10);

$this->assertIsArray($chain->array);
$this->assertCount(10, $chain->array);
}

/**
* @test
*/
Expand All @@ -69,7 +81,6 @@ public function chainHasTraits(): void
$this->assertTrue(method_exists($c, 'count'));
$this->assertTrue(method_exists($c, 'countValues'));
$this->assertTrue(method_exists($c, 'diff'));
$this->assertTrue(method_exists($c, 'fill'));
$this->assertTrue(method_exists($c, 'filter'));
$this->assertTrue(method_exists($c, 'find'));
$this->assertTrue(method_exists($c, 'first'));
Expand Down
37 changes: 0 additions & 37 deletions tests/Link/FillTest.php

This file was deleted.