|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
7
|
|
|
|
|
8
|
|
|
use App\Model\DeckShuffler; |
|
9
|
|
|
use App\Model\CardDealer; |
|
10
|
|
|
use App\Model\FrenchSuitedDeck; |
|
11
|
|
|
use App\Observer\SessionSavingObserver; |
|
12
|
|
|
use Random\Randomizer; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class DeckService |
|
15
|
|
|
{ |
|
16
|
|
|
public function getInstansiatedDeck(Request $request, string $deckName): FrenchSuitedDeck |
|
17
|
|
|
{ |
|
18
|
|
|
$observers = [ |
|
19
|
|
|
new SessionSavingObserver($request, $deckName) |
|
20
|
|
|
]; |
|
21
|
|
|
return FrenchSuitedDeck::createFromSession($request->getSession()->get($deckName), $observers); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getDeck(Request $request): JsonResponse |
|
25
|
|
|
{ |
|
26
|
|
|
$deck = $this->getInstansiatedDeck($request, 'deck_2'); |
|
27
|
|
|
$deck->sort(); |
|
28
|
|
|
|
|
29
|
|
|
return new JsonResponse($deck->getDeck()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function shuffleDeck(Request $request): JsonResponse |
|
33
|
|
|
{ |
|
34
|
|
|
$deck = $this->getInstansiatedDeck($request, 'deck_2'); |
|
35
|
|
|
$deckShuffler = new DeckShuffler(new Randomizer()); |
|
36
|
|
|
$deckShuffler->shuffle($deck); |
|
37
|
|
|
|
|
38
|
|
|
return new JsonResponse($deck->getDeck()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function drawCard(Request $request): JsonResponse |
|
42
|
|
|
{ |
|
43
|
|
|
$deck = $this->getInstansiatedDeck($request, 'deck_2'); |
|
44
|
|
|
$card = $deck->cardCollection->drawCards(1); |
|
45
|
|
|
|
|
46
|
|
|
return new JsonResponse($card); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function drawCards(int $number, Request $request): JsonResponse |
|
50
|
|
|
{ |
|
51
|
|
|
$deck = $this->getInstansiatedDeck($request, 'deck_2'); |
|
52
|
|
|
$cards = $deck->cardCollection->drawCards($number); |
|
53
|
|
|
|
|
54
|
|
|
return new JsonResponse($cards); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function dealCards(int $players, int $cards, Request $request): JsonResponse |
|
58
|
|
|
{ |
|
59
|
|
|
$deck = $this->getInstansiatedDeck($request, 'deck_2'); |
|
60
|
|
|
$cardDealer = new CardDealer(); |
|
61
|
|
|
$hands = $cardDealer->deal($deck, $players, $cards); |
|
62
|
|
|
return new JsonResponse($hands); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function resetDeck(Request $request): JsonResponse |
|
66
|
|
|
{ |
|
67
|
|
|
$session = $request->getSession(); |
|
68
|
|
|
$session->clear(); |
|
69
|
|
|
|
|
70
|
|
|
return new JsonResponse(['message' => 'Deck reset!']); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths