Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit d2e71d5

Browse files
committed
Reviewed and edited #13
1 parent f5d811d commit d2e71d5

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

src/Hydrator/Iterator/HydratingArrayIterator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class HydratingArrayIterator extends HydratingIteratorIterator
2424
*/
2525
protected $prototype;
2626

27+
/**
28+
* @param HydratorInterface $hydrator
29+
* @param array $data
30+
* @param string|object $prototype Object, or class name to use for prototype.
31+
*/
2732
public function __construct(HydratorInterface $hydrator, array $data, $prototype)
2833
{
2934
parent::__construct($hydrator, new ArrayIterator($data), $prototype);

src/Hydrator/Iterator/HydratingIteratorInterface.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
interface HydratingIteratorInterface extends Iterator
1616
{
1717
/**
18-
* This sets the prototype of that will be hydrated. This can be the name of the class or
19-
* the object itself. The iterator will clone the object
18+
* This sets the prototype to hydrate.
19+
*
20+
* This prototype can be the name of the class or the object itself;
21+
* iteration will clone the object.
2022
*
2123
* @param string|object $prototype
2224
*/
2325
public function setPrototype($prototype);
2426

2527
/**
26-
* Sets the hydrator to use for the prototype
28+
* Sets the hydrator to use during iteration.
2729
*
2830
* @param HydratorInterface $hydrator
2931
*/

src/Hydrator/Iterator/HydratingIteratorIterator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@ class HydratingIteratorIterator extends IteratorIterator implements HydratingIte
2626
*/
2727
protected $prototype;
2828

29+
/**
30+
* @param HydratorInterface $hydrator
31+
* @param Iterator $data
32+
* @param string|object $prototype Object or class name to use for prototype.
33+
*/
2934
public function __construct(HydratorInterface $hydrator, Iterator $data, $prototype)
3035
{
3136
$this->setHydrator($hydrator);
3237
$this->setPrototype($prototype);
3338
parent::__construct($data);
3439
}
3540

41+
/**
42+
* @inheritdoc
43+
*/
3644
public function setPrototype($prototype)
3745
{
3846
if (is_object($prototype)) {
@@ -49,11 +57,17 @@ public function setPrototype($prototype)
4957
$this->prototype = new $prototype;
5058
}
5159

60+
/**
61+
* @inheritdoc
62+
*/
5263
public function setHydrator(HydratorInterface $hydrator)
5364
{
5465
$this->hydrator = $hydrator;
5566
}
5667

68+
/**
69+
* @return object Returns hydrated clone of $prototype
70+
*/
5771
public function current()
5872
{
5973
$currentValue = parent::current();

test/Hydrator/Iterator/HydratingArrayIteratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testHydratesObjectAndClonesOnCurrent()
1919
{
2020
$data = [
2121
['foo' => 'bar'],
22-
['baz' => 'bat']
22+
['baz' => 'bat'],
2323
];
2424

2525
$object = new ArrayObject();
@@ -41,7 +41,7 @@ public function testHydratesObjectAndClonesOnCurrent()
4141
public function testUsingStringForObjectName()
4242
{
4343
$data = [
44-
['foo' => 'bar']
44+
['foo' => 'bar'],
4545
];
4646

4747
$hydratingIterator = new HydratingArrayIterator(new ArraySerializable(), $data, '\ArrayObject');

test/Hydrator/Iterator/HydratingIteratorIteratorTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testHydratesObjectAndClonesOnCurrent()
2020
{
2121
$data = [
2222
['foo' => 'bar'],
23-
['baz' => 'bat']
23+
['baz' => 'bat'],
2424
];
2525

2626
$iterator = new ArrayIterator($data);
@@ -43,7 +43,7 @@ public function testHydratesObjectAndClonesOnCurrent()
4343
public function testUsingStringForObjectName()
4444
{
4545
$data = [
46-
['foo' => 'bar']
46+
['foo' => 'bar'],
4747
];
4848

4949
$iterator = new ArrayIterator($data);
@@ -57,6 +57,10 @@ public function testUsingStringForObjectName()
5757
public function testThrowingInvalidArguementExceptionWhenSettingPrototypeToInvalidClass()
5858
{
5959
$this->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException');
60-
$hydratingIterator = new HydratingIteratorIterator(new ArraySerializable(), new ArrayIterator(), 'not a real class');
60+
$hydratingIterator = new HydratingIteratorIterator(
61+
new ArraySerializable(),
62+
new ArrayIterator(),
63+
'not a real class'
64+
);
6165
}
6266
}

0 commit comments

Comments
 (0)