public function createLocation(User $user, $ifnotexists = false) { if ($ifnotexists === false || $this->anyLocationExists($user) === false) { $loc = new Location($user); if ($loc !== null) { $generator = new SecureRandom(); $loc->setPassword(bin2hex($generator->nextBytes(2))); $loc->setCaption($this->translator->trans('Location') . " #" . ($this->totalCount($user) + 1)); return $loc; } } return null; }