/**
* Sets a media with a given id as the avatar of a given contact.
*
* @param Contact $contact
* @param array $avatar with id property
*
* @throws EntityNotFoundException
*/
private function setAvatar(Contact $contact, $avatar)
{
$mediaEntity = null;
if (is_array($avatar) && $this->getProperty($avatar, 'id')) {
$mediaId = $this->getProperty($avatar, 'id');
$mediaEntity = $this->mediaRepository->findMediaById($mediaId);
if (!$mediaEntity) {
throw new EntityNotFoundException($this->mediaRepository->getClassName(), $mediaId);
}
}
$contact->setAvatar($mediaEntity);
}