Issues (17)

src/Controller/GameController.php (1 issue)

Severity
1
<?php
2
3
namespace App\Controller;
4
5
use App\Card\Card;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Session\SessionInterface;
11
use App\Card\DeckOfCards;
12
use App\Card\Game;
13
use App\Card\Draw;
14
use App\Card\SessionGameMethods;
15
16
class GameController extends AbstractController
17
{
18
    #[Route("/game", name: "game")]
19
    public function game(): Response
20
    {
21
        return $this->render('card/game.html.twig');
22
    }
23
24
    #[Route("/game/doc", name: "doc")]
25
    public function doc(): Response
26
    {
27
        return $this->render('card/doc.html.twig');
28
    }
29
30
    #[Route("/game", name: "start_game")]
31
    public function start(): Response
32
    {
33
        return $this->render('card/game.html.twig');
34
    }
35
36
    #[Route("/game/play", name: "play", methods: ["GET", "POST"])]
37
    public function play(SessionInterface $session, Request $request): Response
38
    {
39
        if ($request->request->get('restartCard')) {
40
            $sessionMethods = new SessionGameMethods();
41
            // $game = new Game($session);
42
            $sessionMethods->resetGame($session);
43
            return $this->redirectToRoute('play');
44
        }
45
46
        $sessionMethods = new SessionGameMethods();
47
        // $game = new Game($session);
48
        $sessionMethods->sessionGame($session);
49
        $returnGame = $sessionMethods->returnGame($session);
50
51
        return $this->render('card/play.html.twig', $returnGame);
52
    }
53
54
    #[Route("/game/draw", name: "draw_game", methods: ["POST"])]
55
    public function drawGame(SessionInterface $session): Response
56
    {
57
        $deck = $session->get('deck');
58
        if (!$deck instanceof DeckOfCards || $deck->countCards() <= 0) {
59
            $deck = new DeckOfCards();
60
            $deck->shuffleCards();
61
        }
62
63
        $playerHand = $session->get('playerHand', []);
64
        $playerScore = $session->get('playerScore', 0);
65
66
        $draw = new Draw();
67
        $result = $draw->playerDraw($playerHand, $deck);
68
69
        $session->set('deck', $result['deck']);
70
        $session->set('playerHand', $result['hand']);
71
        $session->set('playerScore', $playerScore + (int) $result['score']);
72
73
        return $this->redirectToRoute('play');
74
    }
75
76
    #[Route("/game/stop", name: "stop_game", methods: ["POST"])]
77
    public function stopGame(SessionInterface $session): Response
78
    {
79
        $deck = $session->get('deck');
80
        if (!$deck instanceof DeckOfCards || $deck->countCards() <= 0) {
81
            $deck = new DeckOfCards();
82
            $deck->shuffleCards();
83
        }
84
85
        $bankHand = $session->get('bankHand', []);
86
        $bankScore = $session->get('bankScore', 0);
87
88
        $draw = new Draw();
89
        $result = $draw->bankDraw($bankHand, $deck);
90
91
        $session->set('deck', $result['deck']);
92
        $session->set('bankHand', $result['hand']);
93
        $session->set('bankScore', $bankScore + $result['score']);
94
95
        $sessionMethods = new SessionGameMethods($session);
0 ignored issues
show
The call to App\Card\SessionGameMethods::__construct() has too many arguments starting with $session. ( Ignorable by Annotation )

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

95
        $sessionMethods = /** @scrutinizer ignore-call */ new SessionGameMethods($session);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
96
        $data = $sessionMethods->gameData($session);
97
98
        return $this->render('card/result.html.twig', $data);
99
    }
100
}
101