fix(entity): re-index ContributionCollection constructor arguments
array_map() over the variadic constructor can produce non-sequential or string keys, which doesn't match the array<int, Contribution> property type; re-index with array_values(). Also documents the iterator/count accessors.
This commit is contained in:
@@ -14,14 +14,16 @@ final class ContributionCollection implements \IteratorAggregate, \Countable
|
|||||||
|
|
||||||
public function __construct(Contribution ...$contributions)
|
public function __construct(Contribution ...$contributions)
|
||||||
{
|
{
|
||||||
$this->contributions = $contributions;
|
$this->contributions = array_values($contributions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return \ArrayIterator<int, Contribution> */
|
||||||
public function getIterator(): \ArrayIterator
|
public function getIterator(): \ArrayIterator
|
||||||
{
|
{
|
||||||
return new \ArrayIterator($this->contributions);
|
return new \ArrayIterator($this->contributions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Number of contributions held in this collection. */
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
return count($this->contributions);
|
return count($this->contributions);
|
||||||
|
|||||||
Reference in New Issue
Block a user