for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Fiv\Collection;
/**
* @author Ivan Shcherbak <[email protected]> 11/7/14
*/
abstract class TypedCollection extends BaseCollection {
* You can add or append only one type of items to this collection
*
* @param $item
* @throws \Exception
public abstract function validateType($item);
* @inheritdoc
public function prepend($item) {
$this->validateType($item);
return parent::prepend($item);
}
public function append($item) {
return parent::append($item);
public function addAfter($index, $items) {
if (!is_array($items)) {
throw new \InvalidArgumentException('You can add after only array of items');
foreach ($items as $item) {
return parent::addAfter($index, $items);
public function setItems($items) {
throw new \InvalidArgumentException("You can set only array of items");
foreach ($items as $key => $item) {
return parent::setItems($items);
public function offsetSet($offset, $item) {
return parent::offsetSet($offset, $item);