/** * @param $data * @return UserEntity */ public function createUser($data) { if (empty($data['email'])) { throw new \InvalidArgumentException('"email" missed'); } if (empty($data['password'])) { throw new \InvalidArgumentException('"password" missed'); } if (empty($data['firstName'])) { throw new \InvalidArgumentException('"firstName" missed'); } if (empty($data['phone'])) { throw new \InvalidArgumentException('"phone" missed'); } if (empty($data['lastName'])) { throw new \InvalidArgumentException('"lastName" missed'); } if ($this->isEmailExist($data['email'])) { throw new \InvalidArgumentException('email "' . $data['email'] . '"" exists already'); } $user = new UserEntity(); $user->populate($data); $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); return $user; }