From 37012efd3c0e18ab0f3aa4e3410112fc71d7ed57 Mon Sep 17 00:00:00 2001 From: Nicolas Reynis Date: Sun, 15 Dec 2019 11:11:15 +0100 Subject: [PATCH] Move static factory method --- src/Chain.php | 20 ++++++++++++++++++-- src/Link/Fill.php | 30 ------------------------------ tests/ChainTest.php | 13 ++++++++++++- tests/Link/FillTest.php | 37 ------------------------------------- 4 files changed, 30 insertions(+), 70 deletions(-) delete mode 100644 src/Link/Fill.php delete mode 100644 tests/Link/FillTest.php diff --git a/src/Chain.php b/src/Chain.php index fa141aa..84860c2 100644 --- a/src/Chain.php +++ b/src/Chain.php @@ -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; @@ -56,7 +55,6 @@ class Chain extends AbstractChain implements Countable use Count; use CountValues; use Diff; - use Fill; use Filter; use Find; use First; @@ -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)); + } } diff --git a/src/Link/Fill.php b/src/Link/Fill.php deleted file mode 100644 index 8a9b553..0000000 --- a/src/Link/Fill.php +++ /dev/null @@ -1,30 +0,0 @@ - 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 */ @@ -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')); diff --git a/tests/Link/FillTest.php b/tests/Link/FillTest.php deleted file mode 100644 index 06ca9b6..0000000 --- a/tests/Link/FillTest.php +++ /dev/null @@ -1,37 +0,0 @@ -assertIsArray($mock->array); - $this->assertCount(10, $mock->array); - } -} - -class ChainMock -{ - use Fill; - - public $array; - - public function __construct($arr) - { - $this->array = $arr; - } -}