for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace BoneMvc\Module\Dragon\Collection;
use BoneMvc\Module\Dragon\Entity\Dragon;
use Doctrine\Common\Collections\ArrayCollection;
use JsonSerializable;
use LogicException;
class DragonCollection extends ArrayCollection implements JsonSerializable
{
/**
* @param Dragon $dragon
* @return $this
* @throws LogicException
*/
public function update(Dragon $dragon)
$key = $this->findKey($dragon);
if($key) {
$this->offsetSet($key,$dragon);
return $this;
}
throw new LogicException('Dragon was not in the collection.');
public function append(Dragon $dragon)
$this->add($dragon);
* @return Dragon|null
public function current()
return parent::current();
* @return bool|int
public function findKey(Dragon $dragon)
$it = $this->getIterator();
$it->rewind();
while($it->valid()) {
if($it->current()->getId() == $dragon->getId()) {
return $it->key();
$it->next();
return false;
* @param int $id
* @return Dragon|bool
public function findById(int $id)
if($it->current()->getId() == $id) {
return $it->current();
* @return array
public function toArray(): array
$collection = [];
/** @var Dragon $row */
$row = $it->current();
$collection[] = $row->toArray();
return $collection;
* @return string
public function jsonSerialize(): string
return \json_encode($this->toArray());
public function __toString(): string
return $this->jsonSerialize();