/** * @param string $id * @return void */ public function delete($id) { $photoId = new PhotoId($id); $photo = $this->repository->findById($photoId); $thumbCollection = $this->thumbRepository->findCollectionBy($photoId); /** @var PhotoThumb $thumb */ foreach ($thumbCollection as $thumb) { if ($this->storage->removeThumb($thumb)) { $this->thumbRepository->delete($thumb); } } if ($this->storage->remove($photo)) { $this->repository->delete($photo); } }