DeckService::getInstansiatedDeck()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 2
b 0
f 1
nc 1
nop 2
dl 0
loc 6
rs 10
ccs 0
cts 4
cp 0
crap 2
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;
0 ignored issues
show
Bug introduced by
The type Random\Randomizer was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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