File tree Expand file tree Collapse file tree 5 files changed +58
-1
lines changed
Expand file tree Collapse file tree 5 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,7 @@ $chain->reduce(function ($current, $value) {
205205- ` ->count() `
206206- ` ->countValues() `
207207- ` ->first() `
208+ - ` ->join([$glue]) `
208209- ` ->last() `
209210- ` ->reduce() `
210211- ` ->sum() `
Original file line number Diff line number Diff line change 1414use Cocur \Chain \Link \Intersect ;
1515use Cocur \Chain \Link \IntersectAssoc ;
1616use Cocur \Chain \Link \IntersectKey ;
17+ use Cocur \Chain \Link \Join ;
1718use Cocur \Chain \Link \Keys ;
1819use Cocur \Chain \Link \Last ;
1920use Cocur \Chain \Link \Map ;
4142 * Chain.
4243 *
4344 * @author Florian Eckerstorfer
44- * @copyright 2015 Florian Eckerstorfer
45+ * @copyright 2015-2017 Florian Eckerstorfer
4546 */
4647class Chain extends AbstractChain implements Countable
4748{
@@ -57,6 +58,7 @@ class Chain extends AbstractChain implements Countable
5758 Intersect,
5859 IntersectAssoc,
5960 IntersectKey,
61+ Join,
6062 Keys,
6163 Last,
6264 Map,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cocur \Chain \Link ;
4+
5+ /**
6+ * Implode.
7+ *
8+ * @author Florian Eckerstorfer
9+ * @copyright 2017 Florian Eckerstorfer
10+ */
11+ trait Join
12+ {
13+ /**
14+ * Join array elements with a string
15+ *
16+ * @param string $glue
17+ *
18+ * @return string Returns a string containing a string representation of all the array elements in the same order,
19+ * with the glue string between each element.
20+ */
21+ public function join ($ glue = '' )
22+ {
23+ return implode ($ glue , $ this ->array );
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ public function chainHasTraits()
6868 $ this ->assertTrue (method_exists ($ c , 'intersect ' ));
6969 $ this ->assertTrue (method_exists ($ c , 'intersectAssoc ' ));
7070 $ this ->assertTrue (method_exists ($ c , 'intersectKey ' ));
71+ $ this ->assertTrue (method_exists ($ c , 'join ' ));
7172 $ this ->assertTrue (method_exists ($ c , 'keys ' ));
7273 $ this ->assertTrue (method_exists ($ c , 'last ' ));
7374 $ this ->assertTrue (method_exists ($ c , 'map ' ));
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cocur \Chain \Link ;
4+
5+ use PHPUnit_Framework_TestCase ;
6+
7+ /**
8+ * CountTest.
9+ *
10+ * @author Florian Eckerstorfer
11+ * @copyright 2015 Florian Eckerstorfer
12+ * @group unit
13+ */
14+ class JoinTest extends PHPUnit_Framework_TestCase
15+ {
16+ /**
17+ * @test
18+ * @covers Cocur\Chain\Link\Join::join()
19+ */
20+ public function joinReturnsStringWithoutGlue ()
21+ {
22+ /** @var \Cocur\Chain\Link\Join $mock */
23+ $ mock = $ this ->getMockForTrait ('Cocur\Chain\Link\Join ' );
24+ $ mock ->array = ['a ' , 'b ' , 'c ' ];
25+
26+ $ this ->assertEquals ('abc ' , $ mock ->join ());
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments