collectionItemsList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Controller\Admin;
4
5
use App\Repository\ItemRepository;
6
use App\Repository\CollectionRepository;
7
use Psr\Log\LoggerInterface;
8
use Ramsey\Uuid\Uuid;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\Messenger\MessageBusInterface;
13
use Symfony\Component\Routing\Annotation\Route;
14
use Knp\Component\Pager\PaginatorInterface;
15
use Symfony\Component\HttpFoundation\RedirectResponse;
16
use App\Command\RemoveItemFromCollectionCommand;
17
18
class AdminCollectionItemsController extends AbstractController
19
{
20
    /**
21
     * @var MessageBusInterface
22
     */
23
    private $commandBus;
24
    /**
25
     * @var LoggerInterface
26
     */
27
    private $logger;
28
    /**
29
     * @var ItemRepository
30
     */
31
    private $repository;
32
    /**
33
     * @var CollectionRepository
34
     */
35
    private $collectionRepository;
36
37
    /**
38
     * @param MessageBusInterface $commandBus
39
     * @param LoggerInterface $logger
40
     * @param ItemRepository $repository
41
     * @param CollectionRepository $collectionRepository
42
     */
43
    public function __construct(
44
        MessageBusInterface $commandBus,
45
        LoggerInterface $logger,
46
        ItemRepository $repository,
47
        CollectionRepository $collectionRepository
48
    )
49
    {
50
        $this->commandBus = $commandBus;
51
        $this->logger = $logger;
52
        $this->repository = $repository;
53
        $this->collectionRepository = $collectionRepository;
54
    }
55
56
    /** 
57
    * @Route("/admin/collection-items/{id}", name="admin_collection_items", methods={"GET"})
58
     * @param PaginatorInterface $paginator
59
     * @param Request $request
60
     * @return Response
61
     */ 
62
    public function collectionItemsList(string $id, PaginatorInterface $paginator, Request $request): Response
63
    {         
64
        $collectionId = Uuid::fromString($id);
65
        $collection = $this->collectionRepository->getCollection($collectionId);
66
        return $this->render('admin/collection/items_list.html.twig', [ 
67
            'collection' => $collection,
68
            'pagination' => $paginator->paginate(
69
             $this->repository->listAllItemsInCollection($collectionId), $request->query->getInt('page', 1),10) 
70
        ]); 
71
    }
72
73
    /**
74
     * 
75
     * @Route("/admin/delete/item-collection/{itemId}/{collectionId}", name="admin_delete_collection_item", methods={"GET"})
76
     * @param string $itemId
77
     * @param string $collectionId
78
     * @param Request $rawRequest
79
     * @return Response|RedirectResponse
80
     */
81
    public function deleteCollection(string $itemId, string $collectionId, Request $rawRequest): Response
0 ignored issues
show
Unused Code introduced by
The parameter $rawRequest is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

81
    public function deleteCollection(string $itemId, string $collectionId, /** @scrutinizer ignore-unused */ Request $rawRequest): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        try {
84
            $itemId = Uuid::fromString($itemId);
85
            $collectionId = Uuid::fromString($collectionId);
86
            $command = new RemoveItemFromCollectionCommand($itemId, $collectionId);
87
            $this->commandBus->dispatch($command);
88
            $this->addFlash('success','Item removed from collection deleted!');
89
        } catch (\Exception $e) {
90
            $this->addFlash('danger','Error while removing item from collection: '.$e->getMessage());
91
        }
92
93
        return $this->redirectToRoute('admin_collections');
94
    }
95
}
96