Conditions | 16 |
Paths | 723 |
Total Lines | 128 |
Code Lines | 83 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
32 | public function handle($mixed): void |
||
33 | { |
||
34 | /** @var Chart $chart */ |
||
35 | $chart = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Chart')->find($mixed); |
||
36 | if (null === $chart) { |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | $this->groups[$chart->getGroup()->getId()] = $chart->getGroup(); |
||
41 | $this->games[$chart->getGroup()->getGame()->getId()] = $chart->getGroup()->getGame(); |
||
42 | |||
43 | $ranking = $this->playerChartRankingQuery->getRanking($chart); |
||
44 | $pointsChart = Ranking::chartPointProvider(count($ranking)); |
||
45 | |||
46 | $topScoreLibValue = ''; |
||
47 | $previousLibValue = ''; |
||
48 | $rank = 1; |
||
49 | $nbEqual = 1; |
||
50 | $playerChartEqual = []; |
||
51 | |||
52 | $result = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerChart')->getPlatforms($chart); |
||
53 | $platforms = []; |
||
54 | foreach ($result as $row) { |
||
55 | $platforms[$row['id']] = [ |
||
56 | 'count' => $row['nb'], |
||
57 | 'points' => Ranking::platformPointProvider($row['nb']), |
||
58 | 'previousLibValue' => '', |
||
59 | 'rank' => 0, |
||
60 | 'nbEqual' => 1, |
||
61 | 'playerChartEqual' => [], |
||
62 | ]; |
||
63 | } |
||
64 | |||
65 | foreach ($ranking as $k => $item) { |
||
66 | $libValue = ''; |
||
67 | /** @var PlayerChart $playerChart */ |
||
68 | $playerChart = $item[0]; |
||
69 | |||
70 | $this->players[$playerChart->getPlayer()->getId()] = $playerChart->getPlayer(); |
||
71 | |||
72 | // Lost position ? |
||
73 | $oldRank = $playerChart->getRank(); |
||
74 | $oldNbEqual = $playerChart->getNbEqual(); |
||
75 | $playerChart->setTopScore(false); |
||
76 | |||
77 | foreach ($chart->getLibs() as $lib) { |
||
78 | $libValue .= $item['value_' . $lib->getIdLibChart()] . '/'; |
||
79 | } |
||
80 | if ($k === 0) { |
||
81 | // Premier élément => topScore |
||
82 | $playerChart->setTopScore(true); |
||
83 | $topScoreLibValue = $libValue; |
||
84 | } else { |
||
85 | if ($libValue === $topScoreLibValue) { |
||
86 | $playerChart->setTopScore(true); |
||
87 | } |
||
88 | if ($previousLibValue === $libValue) { |
||
89 | ++$nbEqual; |
||
90 | } else { |
||
91 | $rank += $nbEqual; |
||
92 | $nbEqual = 1; |
||
93 | $playerChartEqual = []; |
||
94 | } |
||
95 | |||
96 | } |
||
97 | // Platform point |
||
98 | if ($playerChart->getPlatform() != null) { |
||
99 | $idPlatForm = $playerChart->getPlatform()->getId(); |
||
100 | if ($platforms[$idPlatForm]['previousLibValue'] === $libValue) { |
||
101 | ++$platforms[$idPlatForm]['nbEqual']; |
||
102 | } else { |
||
103 | $platforms[$idPlatForm]['rank'] += $platforms[$idPlatForm]['nbEqual']; |
||
104 | $platforms[$idPlatForm]['nbEqual'] = 1; |
||
105 | $platforms[$idPlatForm]['playerChartEqual'] = []; |
||
106 | } |
||
107 | $platforms[$idPlatForm]['playerChartEqual'][] = $playerChart; |
||
108 | } |
||
109 | |||
110 | $playerChartEqual[] = $playerChart; |
||
111 | |||
112 | $playerChart |
||
113 | ->setNbEqual($nbEqual) |
||
114 | ->setRank($rank) |
||
115 | ->setPointChart((int) ( |
||
116 | array_sum( |
||
117 | array_slice(array_values($pointsChart), $playerChart->getRank() - 1, $playerChart->getNbEqual()) |
||
118 | ) / $playerChart->getNbEqual() |
||
119 | )); |
||
120 | |||
121 | if ($nbEqual > 1) { |
||
122 | // Pour les égalités déjà passées on met à jour le nbEqual et l'attribution des points |
||
123 | foreach ($playerChartEqual as $playerChartToModify) { |
||
124 | $playerChartToModify |
||
125 | ->setNbEqual($nbEqual) |
||
126 | ->setPointChart($playerChart->getPointChart()); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | if ($playerChart->getPlatform() != null) { |
||
131 | $idPlatForm = $playerChart->getPlatform()->getId(); |
||
132 | $playerChart->setPointPlatform((int) ( |
||
133 | array_sum( |
||
134 | array_slice(array_values($platforms[$idPlatForm]['points']), $platforms[$idPlatForm]['rank'] - 1, $platforms[$idPlatForm]['nbEqual']) |
||
135 | ) / $platforms[$idPlatForm]['nbEqual'] |
||
136 | )); |
||
137 | if ($platforms[$idPlatForm]['nbEqual'] > 1) { |
||
138 | // Pour les égalités déjà passées on met à jour le nbEqual et l'attribution des points |
||
139 | foreach ($platforms[$idPlatForm]['playerChartEqual'] as $playerChartToModify) { |
||
140 | $playerChartToModify |
||
141 | ->setPointPlatform($playerChart->getPointPlatform()); |
||
142 | } |
||
143 | } |
||
144 | } else { |
||
145 | $playerChart->setPointPlatform(0); |
||
146 | } |
||
147 | |||
148 | |||
149 | $event = new PlayerChartEvent($playerChart, $oldRank, $oldNbEqual); |
||
150 | $this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::PLAYER_CHART_MAJ_COMPLETED); |
||
151 | |||
152 | $previousLibValue = $libValue; |
||
153 | |||
154 | // Platform point |
||
155 | if ($playerChart->getPlatform() != null) { |
||
156 | $platforms[$playerChart->getPlatform()->getId()]['previousLibValue'] = $libValue; |
||
157 | } |
||
158 | } |
||
159 | $this->em->flush(); |
||
160 | } |
||
177 |
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