From 00bc65e491fe2053f1bdb9c5c49ab7cddda0025d Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 5 Mar 2025 16:35:04 +0100 Subject: [PATCH] Implement IteratorAggregate for Resolution::class --- src/Resolution.php | 19 ++++++++++++++++++- tests/Unit/ResolutionTest.php | 8 ++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Resolution.php b/src/Resolution.php index 6dd13077..1e614ce3 100644 --- a/src/Resolution.php +++ b/src/Resolution.php @@ -4,10 +4,16 @@ declare(strict_types=1); namespace Intervention\Image; +use ArrayIterator; use Intervention\Image\Interfaces\ResolutionInterface; +use IteratorAggregate; use Stringable; +use Traversable; -class Resolution implements ResolutionInterface, Stringable +/** + * @implements IteratorAggregate + */ +class Resolution implements ResolutionInterface, Stringable, IteratorAggregate { public const PER_INCH = 1; public const PER_CM = 2; @@ -24,6 +30,17 @@ class Resolution implements ResolutionInterface, Stringable protected float $y, protected int $per_unit = self::PER_INCH ) { + // + } + + /** + * {@inheritdoc} + * + * @see IteratorAggregate::getIterator() + */ + public function getIterator(): Traversable + { + return new ArrayIterator([$this->x, $this->y]); } /** diff --git a/tests/Unit/ResolutionTest.php b/tests/Unit/ResolutionTest.php index 6986b89d..d81a520d 100644 --- a/tests/Unit/ResolutionTest.php +++ b/tests/Unit/ResolutionTest.php @@ -17,6 +17,14 @@ final class ResolutionTest extends BaseTestCase $this->assertInstanceOf(Resolution::class, $resolution); } + public function testIteration(): void + { + $resolution = new Resolution(1.2, 3.4); + foreach ($resolution as $value) { + $this->assertIsFloat($value); + } + } + public function testXY(): void { $resolution = new Resolution(1.2, 3.4);