RankingUpdateDispatcher   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A updatePlayerRankFromGame() 0 4 2
A updateTeamRankFromPlayer() 0 5 2
A updatePlayerRankFromGroup() 0 4 2
A __construct() 0 3 1
A updatePlayerRankFromPlayer() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Message\Dispatcher;
6
7
use Symfony\Component\Messenger\Exception\ExceptionInterface;
8
use Symfony\Component\Messenger\MessageBusInterface;
9
use VideoGamesRecords\CoreBundle\Entity\Game;
10
use VideoGamesRecords\CoreBundle\Entity\Group;
11
use VideoGamesRecords\CoreBundle\Entity\Player;
12
use VideoGamesRecords\CoreBundle\Entity\PlayerChart;
13
use VideoGamesRecords\CoreBundle\Message\Player\UpdatePlayerChartRank;
14
use VideoGamesRecords\CoreBundle\Message\Player\UpdatePlayerData;
15
use VideoGamesRecords\CoreBundle\Message\Player\UpdatePlayerRank;
16
use VideoGamesRecords\CoreBundle\Message\Team\UpdateTeamChartRank;
17
18
readonly class RankingUpdateDispatcher
19
{
20
    public function __construct(
21
        private MessageBusInterface $bus,
22
    ) {
23
    }
24
25
    /**
26
     * @param Game $game
27
     * @throws ExceptionInterface
28
     */
29
    public function updatePlayerRankFromGame(Game $game): void
30
    {
31
        foreach ($game->getGroups() as $group) {
32
            $this->updatePlayerRankFromGroup($group);
33
        }
34
    }
35
36
    /**
37
     * @param Group $group
38
     * @throws ExceptionInterface
39
     */
40
    public function updatePlayerRankFromGroup(Group $group): void
41
    {
42
        foreach ($group->getCharts() as $chart) {
43
            $this->bus->dispatch(new UpdatePlayerChartRank($chart->getId()));
44
        }
45
    }
46
47
    /**
48
     * @param Player $player
49
     * @throws ExceptionInterface
50
     */
51
    public function updateTeamRankFromPlayer(Player $player): void
52
    {
53
        /** @var PlayerChart $playerChart */
54
        foreach ($player->getPlayerCharts() as $playerChart) {
55
            $this->bus->dispatch(new UpdateTeamChartRank($playerChart->getChart()->getId()));
56
        }
57
    }
58
59
    /**
60
     * @param Player $player
61
     * @throws ExceptionInterface
62
     */
63
    public function updatePlayerRankFromPlayer(Player $player): void
64
    {
65
        $this->bus->dispatch(new UpdatePlayerData($player->getId()));
0 ignored issues
show
Bug introduced by
It seems like $player->getId() can also be of type null; however, parameter $playerId of VideoGamesRecords\CoreBu...ayerData::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

65
        $this->bus->dispatch(new UpdatePlayerData(/** @scrutinizer ignore-type */ $player->getId()));
Loading history...
66
        $this->bus->dispatch(new UpdatePlayerRank());
67
    }
68
}
69