From 05aaa1d4e1bd2878b40dafe9954b8d393143de49 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sat, 23 Feb 2019 21:10:53 +0300 Subject: [PATCH] Fixing circular dependency in UserFactory. --- .../Service/Factory/UserFactory.php | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/UserFactory.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/UserFactory.php index 016b86a..752b50b 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/UserFactory.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/UserFactory.php @@ -7,7 +7,6 @@ use Skobkin\Bundle\PointToolsBundle\DTO\Api\User as UserDTO; use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository; use Skobkin\Bundle\PointToolsBundle\Exception\Factory\InvalidUserDataException; -use Skobkin\Bundle\PointToolsBundle\Service\Api\UserApi; class UserFactory extends AbstractFactory { @@ -16,29 +15,10 @@ class UserFactory extends AbstractFactory /** @var UserRepository */ private $userRepository; - /** @var UserApi */ - private $userApi; - - public function __construct(LoggerInterface $logger, UserRepository $userRepository, UserApi $userApi) + public function __construct(LoggerInterface $logger, UserRepository $userRepository) { parent::__construct($logger); $this->userRepository = $userRepository; - $this->userApi = $userApi; - } - - public function findOrCreateByLogin(string $login, bool $retrieveMissingFromApi = true): User - { - /** @var User $user */ - if (null === $user = $this->userRepository->findBy(['login' => $login])) { - if ($retrieveMissingFromApi) { - $user = $this->userApi->getUserByLogin($login); - } else { - // TODO neen more specific exception - throw new \RuntimeException(sprintf('User \'%s\' not found in the database. Api retrieval disabled.', $login)); - } - } - - return $user; } /** @@ -60,7 +40,7 @@ class UserFactory extends AbstractFactory if (null === ($user = $this->userRepository->find($userData->getId()))) { $user = new User( $userData->getId(), - \DateTime::createFromFormat('Y-m-d_H:i:s', $userData->getCreated()) ?: new \DateTime() + \DateTime::createFromFormat(self::DATE_FORMAT, $userData->getCreated()) ?: new \DateTime() ); $this->userRepository->add($user); }