1 | <?php |
||
2 | |||
3 | namespace App\Card; |
||
4 | |||
5 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
||
6 | use App\Card\SessionGameMethods; |
||
7 | |||
8 | class JsonGameFormat |
||
9 | { |
||
10 | private $session; |
||
11 | |||
12 | public function __construct(SessionInterface $session) |
||
13 | { |
||
14 | $this->session = $session; |
||
15 | } |
||
16 | |||
17 | public function jsonGame(SessionInterface $session): array |
||
18 | { |
||
19 | $game = new SessionGameMethods($session); |
||
0 ignored issues
–
show
|
|||
20 | $result = $game->sessionGame($session); |
||
21 | |||
22 | $playerHand = $result['playerHand']; |
||
23 | $bankHand = $result['bankHand']; |
||
24 | $playerScore = $result['playerScore']; |
||
25 | $bankScore = $result['bankScore']; |
||
26 | |||
27 | $playerCards = []; |
||
28 | foreach ($playerHand as $card) { |
||
29 | $playerCards[] = [ |
||
30 | 'value' => match ($card->getValue()) { |
||
31 | 1 => 'A', |
||
32 | 11 => 'J', |
||
33 | 12 => 'Q', |
||
34 | 13 => 'K', |
||
35 | default => (string) $card->getValue() |
||
36 | }, |
||
37 | 'suit' => $card->getSuitAsWord() |
||
38 | ]; |
||
39 | } |
||
40 | |||
41 | $bankCards = []; |
||
42 | foreach ($bankHand as $card) { |
||
43 | $bankCards[] = [ |
||
44 | 'value' => match ($card->getValue()) { |
||
45 | 1 => 'A', |
||
46 | 11 => 'J', |
||
47 | 12 => 'Q', |
||
48 | 13 => 'K', |
||
49 | default => (string) $card->getValue() |
||
50 | }, |
||
51 | 'suit' => $card->getSuitAsWord() |
||
52 | ]; |
||
53 | } |
||
54 | |||
55 | return [ |
||
56 | 'player' => [ |
||
57 | 'hand' => $playerCards, |
||
58 | 'score' => $playerScore, |
||
59 | ], |
||
60 | 'bank' => [ |
||
61 | 'hand' => $bankCards, |
||
62 | 'score' => $bankScore, |
||
63 | ] |
||
64 | ]; |
||
65 | } |
||
66 | } |
||
67 |
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.