mirror of
https://github.com/Intervention/image.git
synced 2025-08-15 02:14:03 +02:00
Implement IteratorAggregate for Resolution::class
This commit is contained in:
@@ -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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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);
|
||||||
|
Reference in New Issue
Block a user