/** * @param Pub $toBeAdded * @throws \PubAlreadyExistsException */ public function add(\model\Pub $toBeAdded) { foreach ($this->pubs as $pub) { if ($toBeAdded->isSame($pub)) { throw new \PubAlreadyExistsException("Pub already exists"); } } $this->pubs[$toBeAdded->getId()] = $toBeAdded; }