diff --git a/.env b/.env index 29c9843..a2e04b1 100644 --- a/.env +++ b/.env @@ -44,4 +44,3 @@ MESSENGER_TRANSPORT_DSN=amqp://admin:admin@enjoybooks_rabbitmq_1:5672/%2f/messag # MESSENGER_TRANSPORT_DSN=doctrine://default # MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages ###< symfony/messenger ### - diff --git a/src/Command/UpdateBooksCommand.php b/src/Command/UpdateBooksCommand.php index 49c7872..13d06a0 100644 --- a/src/Command/UpdateBooksCommand.php +++ b/src/Command/UpdateBooksCommand.php @@ -1,10 +1,10 @@ bookUploader = $bookUploader; $this->em = $em; $this->saveBook = $saveBook; parent::__construct(); - $this->listOfAuthors = $listOfAuthors; $this->bus = $bus; $this->notifiedUser = $notifiedUser; } @@ -66,18 +52,13 @@ protected function configure() ; } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - * @throws \Exception - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output) :int { $date = new DateTime('now'); $output->writeln(date_format($date, 'd/m/Y H:i:s').' : command launch'); // Get all authors - $authors = $this->listOfAuthors->getAuthors(); + $authors = $this->em->getRepository(Author::class)->findAll(); + // Get all books which are not in database $books = $this->bookUploader->getAllBooks($authors); diff --git a/src/Controller/AuthorController.php b/src/Controller/AuthorController.php index 7f947c8..a511a64 100644 --- a/src/Controller/AuthorController.php +++ b/src/Controller/AuthorController.php @@ -2,9 +2,10 @@ namespace App\Controller; -use App\Service\Authors\GetListOfAuthors; +use App\Entity\Author; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class AuthorController extends AbstractController @@ -12,24 +13,19 @@ class AuthorController extends AbstractController /** * @var EntityManagerInterface */ - private $entityManager; - /** - * @var GetListOfAuthors - */ - private $listOfAuthors; + private $em; - public function __construct(EntityManagerInterface $entityManager, GetListOfAuthors $listOfAuthors) + public function __construct(EntityManagerInterface $em) { - $this->entityManager = $entityManager; - $this->listOfAuthors = $listOfAuthors; + $this->em = $em; } /** * @Route("/author", name="author") */ - public function listAuthors() + public function listAuthors(): Response { - $authors = $this->listOfAuthors->getAuthors(); + $authors = $this->em->getRepository(Author::class)->findAll(); return $this->render('author/index.html.twig', ["authors" => $authors]); diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php index cf59d4b..90d4af8 100644 --- a/src/Controller/BookController.php +++ b/src/Controller/BookController.php @@ -29,9 +29,6 @@ public function __construct(EntityManagerInterface $entityManager, GetListOfBook /** * @Route("/books", name="books") - * @param Request $request - * @param PaginatorInterface $paginator - * @return Response */ public function listAllBooks(Request $request, PaginatorInterface $paginator): Response { @@ -50,12 +47,8 @@ public function listAllBooks(Request $request, PaginatorInterface $paginator): R /** * @Route("/book/{authorId}", name="bookByAuthor") - * @param $authorId - * @param Request $request - * @param PaginatorInterface $paginator - * @return Response */ - public function listBooksByAuthor($authorId, Request $request, PaginatorInterface $paginator) + public function listBooksByAuthor($authorId, Request $request, PaginatorInterface $paginator): Response { $data = $this->listOfBooks->getBookByAuthors($authorId); diff --git a/src/Controller/GoogleController.php b/src/Controller/GoogleController.php index a5c9369..38946cb 100644 --- a/src/Controller/GoogleController.php +++ b/src/Controller/GoogleController.php @@ -5,7 +5,6 @@ use KnpU\OAuth2ClientBundle\Client\ClientRegistry; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; class GoogleController extends AbstractController @@ -35,7 +34,6 @@ public function connectAction(ClientRegistry $clientRegistry): RedirectResponse * * * @Route("/connect/google/check", name="connect_google_check") - * @return RedirectResponse */ public function connectCheckAction(): RedirectResponse { diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index e738e35..790f101 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -3,6 +3,7 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class IndexController extends AbstractController @@ -10,7 +11,7 @@ class IndexController extends AbstractController /** * @Route("/home", name="home") */ - public function home() + public function home(): Response { return $this->render('home.html.twig'); } diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 62ada4a..2e48e1d 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -12,8 +12,6 @@ class SecurityController extends AbstractController { /** * @Route("/login", name="login") - * @param AuthenticationUtils $authenticationUtils - * @return Response */ public function login(AuthenticationUtils $authenticationUtils): Response { @@ -32,7 +30,7 @@ public function login(AuthenticationUtils $authenticationUtils): Response * @Route("/logout", name="logout") * @throws Exception */ - public function logout() + public function logout(): Exception { throw new Exception('Will be intercepted before getting here'); } diff --git a/src/Controller/SubscriptionController.php b/src/Controller/SubscriptionController.php index 4f826b9..f52b2bf 100644 --- a/src/Controller/SubscriptionController.php +++ b/src/Controller/SubscriptionController.php @@ -4,10 +4,11 @@ namespace App\Controller; +use App\Entity\Author; use App\Form\SubscriptionFormType; -use App\Service\Authors\GetListOfAuthors; use App\Service\Subscriptions\AddSubscriptionService; use App\Service\Subscriptions\GetUserSubscriptionService; +use Doctrine\ORM\EntityManagerInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -21,38 +22,30 @@ class SubscriptionController extends AbstractController * @var GetUserSubscriptionService */ private $userSubscriptionService; - /** - * @var GetListOfAuthors - */ - private $listOfAuthors; /** * @var AddSubscriptionService */ private $addSubscriptionService; - /** - * SubscriptionController constructor. - * @param GetUserSubscriptionService $userSubscriptionService - * @param GetListOfAuthors $listOfAuthors - * @param AddSubscriptionService $addSubscriptionService + * @var EntityManagerInterface */ - public function __construct(GetUserSubscriptionService $userSubscriptionService, GetListOfAuthors $listOfAuthors, AddSubscriptionService $addSubscriptionService) + private $em; + + public function __construct(EntityManagerInterface $em, GetUserSubscriptionService $userSubscriptionService, AddSubscriptionService $addSubscriptionService) { $this->userSubscriptionService = $userSubscriptionService; - $this->listOfAuthors = $listOfAuthors; $this->addSubscriptionService = $addSubscriptionService; + $this->em = $em; } /** * @Route("/subscription/{userId}", name="subscription") - * @param $userId - * @return Response * @IsGranted("ROLE_USER") */ public function getSubscriptions($userId): Response { $subscriptions = $this->userSubscriptionService->getUserSubscriptions($userId); - $authors = $this->listOfAuthors->getAuthors(); + $authors = $this->em->getRepository(Author::class)->findAll(); return $this->render('subscription/subscription.html.twig', ["subscriptions" => $subscriptions, @@ -61,13 +54,11 @@ public function getSubscriptions($userId): Response /** * @Route("/postSubscription", name="post_subscription") - * @param Request $request - * @return Response * @IsGranted("ROLE_USER") */ public function post(Request $request): Response { - $authors = $this->listOfAuthors->getAuthors(); + $authors = $this->em->getRepository(Author::class)->findAll(); $nameAuthors = []; foreach ($authors as $author){ diff --git a/src/Entity/Author.php b/src/Entity/Author.php index b139d1b..44a6c5d 100644 --- a/src/Entity/Author.php +++ b/src/Entity/Author.php @@ -2,13 +2,12 @@ namespace App\Entity; -use App\Repository\AuthorRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=AuthorRepository::class) + * @ORM\Entity() */ class Author { diff --git a/src/Entity/User.php b/src/Entity/User.php index f1427c6..a7314f1 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -2,15 +2,16 @@ namespace App\Entity; -use App\Repository\UserRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; + /** - * @ORM\Entity(repositoryClass=UserRepository::class) + * @ORM\Entity() */ + class User implements UserInterface { /** diff --git a/src/Repository/AuthorRepository.php b/src/Repository/AuthorRepository.php deleted file mode 100644 index 276e389..0000000 --- a/src/Repository/AuthorRepository.php +++ /dev/null @@ -1,50 +0,0 @@ -createQueryBuilder('a') - ->andWhere('a.exampleField = :val') - ->setParameter('val', $value) - ->orderBy('a.id', 'ASC') - ->setMaxResults(10) - ->getQuery() - ->getResult() - ; - } - */ - - /* - public function findOneBySomeField($value): ?Author - { - return $this->createQueryBuilder('a') - ->andWhere('a.exampleField = :val') - ->setParameter('val', $value) - ->getQuery() - ->getOneOrNullResult() - ; - } - */ -} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php deleted file mode 100644 index 2ebc111..0000000 --- a/src/Repository/UserRepository.php +++ /dev/null @@ -1,50 +0,0 @@ -createQueryBuilder('u') - ->andWhere('u.exampleField = :val') - ->setParameter('val', $value) - ->orderBy('u.id', 'ASC') - ->setMaxResults(10) - ->getQuery() - ->getResult() - ; - } - */ - - /* - public function findOneBySomeField($value): ?User - { - return $this->createQueryBuilder('u') - ->andWhere('u.exampleField = :val') - ->setParameter('val', $value) - ->getQuery() - ->getOneOrNullResult() - ; - } - */ -} diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index b33b117..c9e2b0a 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -2,7 +2,8 @@ namespace App\Security; -use App\Repository\UserRepository; +use App\Entity\User; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; @@ -19,7 +20,7 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator { - private $userRepository; + /** * @var RouterInterface */ @@ -32,13 +33,17 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator * @var UserPasswordEncoderInterface */ private $userPasswordEncoder; + /** + * @var EntityManagerInterface + */ + private $em; - public function __construct(UserRepository $userRepository, RouterInterface $router, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $userPasswordEncoder) + public function __construct(EntityManagerInterface $em, RouterInterface $router, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $userPasswordEncoder) { - $this->userRepository = $userRepository; $this->router = $router; $this->csrfTokenManager = $csrfTokenManager; $this->userPasswordEncoder = $userPasswordEncoder; + $this->em = $em; } public function supports(Request $request) { @@ -69,7 +74,7 @@ public function getUser($credentials, UserProviderInterface $userProvider) throw new InvalidCsrfTokenException(); } - return $this->userRepository->findOneBy(['email' => $credentials['email']]); + return $this->em->getRepository(User::class)->findOneBy(['email' => $credentials['email']]); } public function checkCredentials($credentials, UserInterface $user) diff --git a/src/Service/Authors/GetListOfAuthors.php b/src/Service/Authors/GetListOfAuthors.php deleted file mode 100644 index 414d9a6..0000000 --- a/src/Service/Authors/GetListOfAuthors.php +++ /dev/null @@ -1,30 +0,0 @@ -em = $em; - } - - /** - * @return object[] - */ - public function getAuthors() - { - return $this->em->getRepository(Author::class)->findAll(); - } -} \ No newline at end of file diff --git a/src/Service/BookUploader/AbstractBookUploader.php b/src/Service/BookUploader/AbstractBookUploader.php index 755fbfe..d414295 100644 --- a/src/Service/BookUploader/AbstractBookUploader.php +++ b/src/Service/BookUploader/AbstractBookUploader.php @@ -20,13 +20,6 @@ abstract class AbstractBookUploader implements BookUploaderInterface */ protected $em; - /** - * AbstractBookUploader constructor. - * @param string $url - * @param string $key - * @param HttpClientInterface $client - * @param EntityManagerInterface $em - */ public function __construct(string $url, string $key, HttpClientInterface $client, EntityManagerInterface $em) { $this->url = $url; diff --git a/src/Service/BookUploader/GoogleBookUploader.php b/src/Service/BookUploader/GoogleBookUploader.php index 2bc7fc3..91f7ab6 100644 --- a/src/Service/BookUploader/GoogleBookUploader.php +++ b/src/Service/BookUploader/GoogleBookUploader.php @@ -1,5 +1,6 @@ mailer = $mailer; } - /** - * @param SendNotification $notification - * @return Email - * @throws TransportExceptionInterface - */ public function sendNewBookNotification(SendNotification $notification): Email { $email = (new Email()) diff --git a/src/Service/Notification/NotifiedUser.php b/src/Service/Notification/NotifiedUser.php index 5404e8e..a1d0eff 100644 --- a/src/Service/Notification/NotifiedUser.php +++ b/src/Service/Notification/NotifiedUser.php @@ -1,5 +1,6 @@ em = $em; @@ -40,10 +35,6 @@ public function __construct(EntityManagerInterface $em, GetListOfBooks $listOfBo $this->bus = $bus; } - /** - * @param DateTime $date - * @return int - */ public function personToNotify(DateTime $date): int { $books = $this->listOfBooks->getLastBooks($date); @@ -70,10 +61,6 @@ public function personToNotify(DateTime $date): int } - /** - * @param $message - * @param $email - */ public function dispatchNotification($message, $email) { $this->bus->dispatch(new SendNotification($message, $email), [new AmqpStamp('email')]); diff --git a/src/Service/Subscriptions/AddSubscriptionService.php b/src/Service/Subscriptions/AddSubscriptionService.php index e4938d5..51b837e 100644 --- a/src/Service/Subscriptions/AddSubscriptionService.php +++ b/src/Service/Subscriptions/AddSubscriptionService.php @@ -1,5 +1,6 @@ em = $em; } - /** - * @param User $user - * @param $data - */ + public function addSubscription(User $user, $data) { $authorId = $data['author']; diff --git a/src/Service/Subscriptions/GetUserSubscriptionService.php b/src/Service/Subscriptions/GetUserSubscriptionService.php index c4aa819..0588253 100644 --- a/src/Service/Subscriptions/GetUserSubscriptionService.php +++ b/src/Service/Subscriptions/GetUserSubscriptionService.php @@ -1,5 +1,6 @@