mirror of
https://github.com/Intervention/image.git
synced 2025-08-15 10:23:59 +02:00
Implement IteratorAggregate for Point::class
This commit is contained in:
@@ -4,9 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Geometry;
|
||||
|
||||
use ArrayIterator;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
class Point implements PointInterface
|
||||
/**
|
||||
* @implements IteratorAggregate<int>
|
||||
*/
|
||||
class Point implements PointInterface, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Create new point instance
|
||||
@@ -19,6 +25,17 @@ class Point implements PointInterface
|
||||
protected int $x = 0,
|
||||
protected int $y = 0
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see IteratorAggregate::getIterator()
|
||||
*/
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator([$this->x, $this->y]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -27,6 +27,14 @@ final class PointTest extends BaseTestCase
|
||||
$this->assertEquals(50, $point->y());
|
||||
}
|
||||
|
||||
public function testIteration(): void
|
||||
{
|
||||
$point = new Point(40, 50);
|
||||
foreach ($point as $value) {
|
||||
$this->assertIsInt($value);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetSetX(): void
|
||||
{
|
||||
$point = new Point(0, 0);
|
||||
|
Reference in New Issue
Block a user