1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-15 10:23:59 +02:00

Implement IteratorAggregate for Resolution::class

This commit is contained in:
Oliver Vogel
2025-03-05 16:35:04 +01:00
parent 78e290ae97
commit 00bc65e491
2 changed files with 26 additions and 1 deletions

View File

@@ -4,10 +4,16 @@ declare(strict_types=1);
namespace Intervention\Image; namespace Intervention\Image;
use ArrayIterator;
use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\ResolutionInterface;
use IteratorAggregate;
use Stringable; 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_INCH = 1;
public const PER_CM = 2; public const PER_CM = 2;
@@ -24,6 +30,17 @@ class Resolution implements ResolutionInterface, Stringable
protected float $y, protected float $y,
protected int $per_unit = self::PER_INCH protected int $per_unit = self::PER_INCH
) { ) {
//
}
/**
* {@inheritdoc}
*
* @see IteratorAggregate::getIterator()
*/
public function getIterator(): Traversable
{
return new ArrayIterator([$this->x, $this->y]);
} }
/** /**

View File

@@ -17,6 +17,14 @@ final class ResolutionTest extends BaseTestCase
$this->assertInstanceOf(Resolution::class, $resolution); $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 public function testXY(): void
{ {
$resolution = new Resolution(1.2, 3.4); $resolution = new Resolution(1.2, 3.4);