Passed
Push — develop ( c0c420...1d51ce )
by BENARD
06:14
created

GameAdminController::setVideoProofOnlyAction()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 31
rs 9.2728
cc 5
nc 4
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Controller\Admin;
6
7
use Sonata\AdminBundle\Controller\CRUDController;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use VideoGamesRecords\CoreBundle\Entity\Game;
12
use VideoGamesRecords\CoreBundle\Form\VideoProofOnly;
13
use VideoGamesRecords\CoreBundle\Manager\GameManager;
14
use Yokai\SonataWorkflow\Controller\WorkflowControllerTrait;
15
16
class GameAdminController extends CRUDController
17
{
18
    use WorkflowControllerTrait;
19
20
    private GameManager $gameManager;
21
22
    public function __construct(GameManager $gameManager)
23
    {
24
        $this->gameManager = $gameManager;
25
    }
26
27
    /**
28
     * @param $id
29
     * @return RedirectResponse
30
     */
31
    public function copyAction($id): RedirectResponse
0 ignored issues
show
Unused Code introduced by
The parameter $id 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

31
    public function copyAction(/** @scrutinizer ignore-unused */ $id): RedirectResponse

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...
32
    {
33
        if ($this->admin->hasAccess('create')) {
34
            $game = $this->admin->getSubject();
35
36
            $this->gameManager->copy($game);
37
            $this->addFlash('sonata_flash_success', 'Copied successfully');
38
        }
39
40
        return new RedirectResponse($this->admin->generateUrl('list'));
41
    }
42
43
    /**
44
     * @param $id
45
     * @return RedirectResponse
46
     */
47
    public function majAction($id): RedirectResponse
0 ignored issues
show
Unused Code introduced by
The parameter $id 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

47
    public function majAction(/** @scrutinizer ignore-unused */ $id): RedirectResponse

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...
48
    {
49
        $this->gameManager->maj($this->admin->getSubject());
50
        $this->addFlash('sonata_flash_success', 'Game maj successfully');
51
        return new RedirectResponse($this->admin->generateUrl('list'));
52
    }
53
54
    /**
55
     * @param $id
56
     * @return RedirectResponse
57
     */
58
    public function setProofVideoOnly($id): RedirectResponse
0 ignored issues
show
Unused Code introduced by
The parameter $id 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

58
    public function setProofVideoOnly(/** @scrutinizer ignore-unused */ $id): RedirectResponse

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...
59
    {
60
        $this->gameManager->setProofVideoOnly($this->admin->getSubject());
61
        $this->addFlash('sonata_flash_success', 'Game maj successfully');
62
        return new RedirectResponse($this->admin->generateUrl('list'));
63
    }
64
65
    /**
66
     * @param         $id
67
     * @param Request $request
68
     * @return RedirectResponse|Response
69
     */
70
    public function setVideoProofOnlyAction($id, Request $request): RedirectResponse|Response
0 ignored issues
show
Unused Code introduced by
The parameter $id 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

70
    public function setVideoProofOnlyAction(/** @scrutinizer ignore-unused */ $id, Request $request): RedirectResponse|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...
71
    {
72
        /** @var Game $game */
73
        $game = $this->admin->getSubject();
74
75
        $em = $this->admin->getModelManager()->getEntityManager($this->admin->getClass());
0 ignored issues
show
Bug introduced by
The method getEntityManager() does not exist on Sonata\AdminBundle\Model\ModelManagerInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sonata\AdminBundle\Model\LockInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

75
        $em = $this->admin->getModelManager()->/** @scrutinizer ignore-call */ getEntityManager($this->admin->getClass());
Loading history...
76
        $form = $this->createForm(VideoProofOnly::class);
77
        $form->handleRequest($request);
78
        if ($form->isSubmitted() && $form->isValid()) {
79
            $data = $form->getData();
80
            $isVideoProofOnly = $data['isVideoProofOnly'];
81
            foreach ($game->getGroups() as $group) {
82
                foreach ($group->getCharts() as $chart) {
83
                    $chart->setIsProofVideoOnly($isVideoProofOnly);
84
                }
85
            }
86
            $em->flush();
87
88
            $this->addFlash('sonata_flash_success', 'All charts are updated successfully');
89
            return new RedirectResponse($this->admin->generateUrl('show', ['id' => $game->getId()]));
90
        }
91
92
        return $this->render(
93
            '@VideoGamesRecordsCore/Admin/Form/form.set_video_proof_only.html.twig',
94
            [
95
                'base_template' => '@SonataAdmin/standard_layout.html.twig',
96
                'admin' => $this->admin,
97
                'object' => $game,
98
                'form' => $form,
99
                'title' => $game->getName(),
100
                'action' => 'edit'
101
            ]
102
        );
103
    }
104
}
105