Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
DevFabi committed Jul 20, 2020
1 parent 6a575b7 commit 17cba5f
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 243 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

31 changes: 6 additions & 25 deletions src/Command/UpdateBooksCommand.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

declare(strict_types = 1);

namespace App\Command;


use App\Service\Authors\GetListOfAuthors;
use App\Entity\Author;
use App\Service\Books\SaveBook;
use App\Service\BookUploader\BookUploaderInterface;
use App\Service\Notification\NotifiedUser;
Expand All @@ -21,10 +21,6 @@ class UpdateBooksCommand extends Command

private $em;
private $saveBook;
/**
* @var GetListOfAuthors
*/
private $listOfAuthors;
/**
* @var MessageBusInterface
*/
Expand All @@ -38,22 +34,12 @@ class UpdateBooksCommand extends Command
*/
private $bookUploader;

/**
* UpdateBooksCommand constructor.
* @param BookUploaderInterface $bookUploader
* @param EntityManagerInterface $em
* @param SaveBook $saveBook
* @param GetListOfAuthors $listOfAuthors
* @param MessageBusInterface $bus
* @param NotifiedUser $notifiedUser
*/
public function __construct(BookUploaderInterface $bookUploader, EntityManagerInterface $em, SaveBook $saveBook, GetListOfAuthors $listOfAuthors, MessageBusInterface $bus, NotifiedUser $notifiedUser)
public function __construct(BookUploaderInterface $bookUploader, EntityManagerInterface $em, SaveBook $saveBook, MessageBusInterface $bus, NotifiedUser $notifiedUser)
{
$this->bookUploader = $bookUploader;
$this->em = $em;
$this->saveBook = $saveBook;
parent::__construct();
$this->listOfAuthors = $listOfAuthors;
$this->bus = $bus;
$this->notifiedUser = $notifiedUser;
}
Expand All @@ -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);
Expand Down
18 changes: 7 additions & 11 deletions src/Controller/AuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@

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
{
/**
* @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]);
Expand Down
9 changes: 1 addition & 8 deletions src/Controller/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions src/Controller/GoogleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +34,6 @@ public function connectAction(ClientRegistry $clientRegistry): RedirectResponse
*
*
* @Route("/connect/google/check", name="connect_google_check")
* @return RedirectResponse
*/
public function connectCheckAction(): RedirectResponse
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
/**
* @Route("/home", name="home")
*/
public function home()
public function home(): Response
{
return $this->render('home.html.twig');
}
Expand Down
4 changes: 1 addition & 3 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class SecurityController extends AbstractController
{
/**
* @Route("/login", name="login")
* @param AuthenticationUtils $authenticationUtils
* @return Response
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
Expand All @@ -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');
}
Expand Down
27 changes: 9 additions & 18 deletions src/Controller/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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){
Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
50 changes: 0 additions & 50 deletions src/Repository/AuthorRepository.php

This file was deleted.

Loading

0 comments on commit 17cba5f

Please sign in to comment.