Skip to content

Commit

Permalink
Added a common return type for Collection::getIterator() method (#1889)
Browse files Browse the repository at this point in the history
* Adjusted docblock for collections in order to have common type for getIterator() method

* Added a common interface for iterators
  • Loading branch information
gechetspr authored Jun 27, 2022
1 parent 0f39bb2 commit c3ef974
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Propel/Runtime/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function setData(array $data): void
}

/**
* @return \Propel\Runtime\Collection\CollectionIterator
* @return \Propel\Runtime\Collection\CollectionIterator|\Propel\Runtime\Collection\IteratorInterface
*/
public function getIterator(): Traversable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Runtime/Collection/CollectionIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @extends \ArrayIterator<(int|string), mixed>
*/
class CollectionIterator extends ArrayIterator
class CollectionIterator extends ArrayIterator implements IteratorInterface
{
/**
* @var \Propel\Runtime\Collection\Collection
Expand Down
19 changes: 19 additions & 0 deletions src/Propel/Runtime/Collection/IteratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* MIT License. This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Propel\Runtime\Collection;

use Countable;
use Iterator;

/**
* @extends \Iterator<(int|string), mixed>
*/
interface IteratorInterface extends Iterator, Countable
{
}
4 changes: 1 addition & 3 deletions src/Propel/Runtime/Collection/OnDemandCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ public function fromArray(array $arr): void
throw new ReadOnlyModelException('The On Demand Collection is read only');
}

// IteratorAggregate Interface

/**
* @return \Propel\Runtime\Collection\OnDemandIterator
* @return \Propel\Runtime\Collection\OnDemandIterator|\Propel\Runtime\Collection\IteratorInterface
*/
public function getIterator(): Traversable
{
Expand Down
5 changes: 1 addition & 4 deletions src/Propel/Runtime/Collection/OnDemandIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Propel\Runtime\Collection;

use Iterator;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
use Propel\Runtime\DataFetcher\DataFetcherInterface;
use Propel\Runtime\Exception\PropelException;
Expand All @@ -19,10 +18,8 @@
* Class for iterating over a statement and returning one Propel object at a time
*
* @author Francois Zaninotto
*
* @implements \Iterator<int|string, mixed>
*/
class OnDemandIterator implements Iterator
class OnDemandIterator implements IteratorInterface
{
/**
* @var \Propel\Runtime\Formatter\ObjectFormatter
Expand Down

0 comments on commit c3ef974

Please sign in to comment.