for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Atrapalo\PHPTools\Collection;
/**
* Class EntityStrictCollection
* @package Atrapalo\PHPTools\Collection
*
* @author Guillermo González <[email protected]>
*/
abstract class EntityStrictCollection extends EntityCollection
{
* Collection constructor.
* @param array $entities
* @param bool $allowEntitiesChildren
* @throws \Exception
public function __construct(array $entities, bool $allowEntitiesChildren = false)
if (empty($entities)) {
throw static::customEmptyException();
}
$this->allowEntitiesChildren = $allowEntitiesChildren;
foreach ($entities as $entity) {
$this->add($entity);
* @param int $offset
* @param null $length
* @return static
public function slice(int $offset, $length = null)
$entities = array_slice($this->toArray(), $offset, $length, true);
return new static($entities);
* @return \Exception
public static function customEmptyException(): \Exception
return new \LengthException('Collection can not be empty');