Skip to content

Commit

Permalink
Implement IteratorAggregate for Resolution::class
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Mar 5, 2025
1 parent 78e290a commit 00bc65e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Resolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace Intervention\Image;

use ArrayIterator;
use Intervention\Image\Interfaces\ResolutionInterface;
use IteratorAggregate;
use Stringable;
use Traversable;

class Resolution implements ResolutionInterface, Stringable
/**
* @implements IteratorAggregate<float>
*/
class Resolution implements ResolutionInterface, Stringable, IteratorAggregate
{
public const PER_INCH = 1;
public const PER_CM = 2;
Expand All @@ -24,6 +30,17 @@ public function __construct(
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]);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/ResolutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function testConstructor(): void
$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);
Expand Down

0 comments on commit 00bc65e

Please sign in to comment.