for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Linio\Collection;
use Doctrine\Common\Collections\ArrayCollection;
abstract class TypedCollection extends ArrayCollection
{
/**
* {@inheritdoc}
*/
public function __construct(array $elements = [])
foreach ($elements as $value) {
$this->validateType($value);
}
parent::__construct($elements);
public function offsetSet($offset, $value)
parent::offsetSet($offset, $value);
public function add($value)
parent::add($value);
* @param mixed $value
*
* @throws InvalidArgumentException
protected function validateType($value)
if (!$this->isValidType($value)) {
$type = is_object($value) ? get_class($value) : gettype($value);
throw new \InvalidArgumentException('Unsupported type: ' . $type);
* @return bool
abstract public function isValidType($value);