Skip to content

Commit 00bc65e

Browse files
committed
Implement IteratorAggregate for Resolution::class
1 parent 78e290a commit 00bc65e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Resolution.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
namespace Intervention\Image;
66

7+
use ArrayIterator;
78
use Intervention\Image\Interfaces\ResolutionInterface;
9+
use IteratorAggregate;
810
use Stringable;
11+
use Traversable;
912

10-
class Resolution implements ResolutionInterface, Stringable
13+
/**
14+
* @implements IteratorAggregate<float>
15+
*/
16+
class Resolution implements ResolutionInterface, Stringable, IteratorAggregate
1117
{
1218
public const PER_INCH = 1;
1319
public const PER_CM = 2;
@@ -24,6 +30,17 @@ public function __construct(
2430
protected float $y,
2531
protected int $per_unit = self::PER_INCH
2632
) {
33+
//
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*
39+
* @see IteratorAggregate::getIterator()
40+
*/
41+
public function getIterator(): Traversable
42+
{
43+
return new ArrayIterator([$this->x, $this->y]);
2744
}
2845

2946
/**

tests/Unit/ResolutionTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public function testConstructor(): void
1717
$this->assertInstanceOf(Resolution::class, $resolution);
1818
}
1919

20+
public function testIteration(): void
21+
{
22+
$resolution = new Resolution(1.2, 3.4);
23+
foreach ($resolution as $value) {
24+
$this->assertIsFloat($value);
25+
}
26+
}
27+
2028
public function testXY(): void
2129
{
2230
$resolution = new Resolution(1.2, 3.4);

0 commit comments

Comments
 (0)