Methods static constructor is missing splat ... operator
- Dominant language
- PHP
- Stars
- 5.8k
- Forks
- 284
- PR merge metrics
- No merged PRs in 30d
Description
We have typed collections
```use App\Domain\UserPack\Email\Model\UserEmail;
use Doctrine\Common\Collections\ArrayCollection;
final class UserEmailCollection extends ArrayCollection
{
public function __construct(UserEmail ...$arr)
{
parent::__construct($arr);
}
```
But when we do any function on that collection inside model, entity
```
class User {
public function disableExistingEmails(): void
{
$this->emails->map(static function (UserEmail $relatedEmail) use ($isFallbackEmailToDisable) {...})
```
we get such error
```
...Collection\UserEmailCollection::__construct(): Argument #1 must be of type
App\Domain\UserPack\Email\Model\UserEmail, array given, called in
/var/www/.../vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 99
```
fixing this issue by creating and extending new abstract collection which overrides ArrayCollection functions e.g.
```
namespace App\Domain\Core\Collections;
use Closure;
use Doctrine\Common\Collections\ArrayCollection;
use function array_map;
abstract class AbstractModelCollection extends ArrayCollection
{
public function map(Closure $func)
{
return new static(
...
array_map(
callback: $func,
array : $this->toArray()
)
);
}
}
```
` "doctrine/common": "^3.3.0",`
I wonder if there is other way without overriding and extra bridge abstraction between domain collections and doctrine to fix the error.
Might be a feature request to add splat operator and typed Collection params maybe with interface e.g. CollectionItemInterface
Whatever answer / response, thanks and have a great day / night hehe! ;)
Contributor guide
Assessment
This issue has not been assessed yet.