File tree Expand file tree Collapse file tree 3 files changed +72
-59
lines changed
Expand file tree Collapse file tree 3 files changed +72
-59
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Cocur \Chain ;
4+
5+ use ArrayAccess ;
6+ use ArrayIterator ;
7+ use IteratorAggregate ;
8+
9+ /**
10+ * Chain.
11+ *
12+ * @author Florian Eckerstorfer
13+ * @copyright 2015 Florian Eckerstorfer
14+ */
15+ abstract class AbstractChain implements ArrayAccess, IteratorAggregate
16+ {
17+ /**
18+ * @var array
19+ */
20+ public $ array = [];
21+
22+ /**
23+ * @return ArrayIterator
24+ */
25+ public function getIterator ()
26+ {
27+ return new ArrayIterator ($ this ->array );
28+ }
29+
30+ /**
31+ * @param mixed $offset
32+ *
33+ * @return bool
34+ */
35+ public function offsetExists ($ offset )
36+ {
37+ return isset ($ this ->array [$ offset ]);
38+ }
39+
40+ /**
41+ * @param mixed $offset
42+ *
43+ * @return mixed
44+ */
45+ public function offsetGet ($ offset )
46+ {
47+ return $ this ->array [$ offset ];
48+ }
49+
50+ /**
51+ * @param mixed $offset
52+ * @param mixed $value
53+ */
54+ public function offsetSet ($ offset , $ value )
55+ {
56+ $ this ->array [$ offset ] = $ value ;
57+ }
58+
59+ /**
60+ * @param mixed $offset
61+ */
62+ public function offsetUnset ($ offset )
63+ {
64+ unset($ this ->array [$ offset ]);
65+ }
66+ }
Original file line number Diff line number Diff line change 22
33namespace Cocur \Chain ;
44
5- use ArrayAccess ;
6- use ArrayIterator ;
75use Cocur \Chain \Link \ChangeKeyCase ;
86use Cocur \Chain \Link \Combine ;
97use Cocur \Chain \Link \Count ;
3432use Cocur \Chain \Link \Sum ;
3533use Cocur \Chain \Link \Unique ;
3634use Cocur \Chain \Link \Unshift ;
37- use IteratorAggregate ;
3835
3936/**
4037 * Chain.
4138 *
4239 * @author Florian Eckerstorfer
4340 * @copyright 2015 Florian Eckerstorfer
4441 */
45- class Chain implements ArrayAccess, IteratorAggregate
42+ class Chain extends AbstractChain
4643{
4744 use ChangeKeyCase,
4845 Combine,
@@ -75,11 +72,6 @@ class Chain implements ArrayAccess, IteratorAggregate
7572 Unique,
7673 Unshift;
7774
78- /**
79- * @var array
80- */
81- public $ array = [];
82-
8375 /**
8476 * @param array $array
8577 *
@@ -92,49 +84,4 @@ public static function create(array $array = [])
9284
9385 return $ chain ;
9486 }
95-
96- /**
97- * @return ArrayIterator
98- */
99- public function getIterator ()
100- {
101- return new ArrayIterator ($ this ->array );
102- }
103-
104- /**
105- * @param mixed $offset
106- *
107- * @return bool
108- */
109- public function offsetExists ($ offset )
110- {
111- return isset ($ this ->array [$ offset ]);
112- }
113-
114- /**
115- * @param mixed $offset
116- *
117- * @return mixed
118- */
119- public function offsetGet ($ offset )
120- {
121- return $ this ->array [$ offset ];
122- }
123-
124- /**
125- * @param mixed $offset
126- * @param mixed $value
127- */
128- public function offsetSet ($ offset , $ value )
129- {
130- $ this ->array [$ offset ] = $ value ;
131- }
132-
133- /**
134- * @param mixed $offset
135- */
136- public function offsetUnset ($ offset )
137- {
138- unset($ this ->array [$ offset ]);
139- }
14087}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public function chainHasTraits()
6363
6464 /**
6565 * @test
66- * @covers Cocur\Chain\Chain ::getIterator()
66+ * @covers Cocur\Chain\AbstractChain ::getIterator()
6767 */
6868 public function chainIsTraversable ()
6969 {
@@ -79,10 +79,10 @@ public function chainIsTraversable()
7979
8080 /**
8181 * @test
82- * @covers Cocur\Chain\Chain ::offsetExists()
83- * @covers Cocur\Chain\Chain ::offsetGet()
84- * @covers Cocur\Chain\Chain ::offsetSet()
85- * @covers Cocur\Chain\Chain ::offsetUnset()
82+ * @covers Cocur\Chain\AbstractChain ::offsetExists()
83+ * @covers Cocur\Chain\AbstractChain ::offsetGet()
84+ * @covers Cocur\Chain\AbstractChain ::offsetSet()
85+ * @covers Cocur\Chain\AbstractChain ::offsetUnset()
8686 */
8787 public function chainAllowsArrayAccess ()
8888 {
You can’t perform that action at this time.
0 commit comments