| Conditions | 16 |
| Paths | 29 |
| Total Lines | 94 |
| Code Lines | 58 |
| 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 __invoke(UpdateTeamChartRank $updateTeamChartRank): array |
||
| 33 | { |
||
| 34 | $chart = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Chart') |
||
| 35 | ->find($updateTeamChartRank->getChartId()); |
||
| 36 | if (null == $chart) { |
||
| 37 | return ['error' => 'chart not found']; |
||
| 38 | } |
||
| 39 | |||
| 40 | //----- delete |
||
| 41 | $query = $this->em |
||
| 42 | ->createQuery('DELETE VideoGamesRecords\CoreBundle\Entity\TeamChart tc WHERE tc.chart = :chart'); |
||
| 43 | $query->setParameter('chart', $chart); |
||
| 44 | $query->execute(); |
||
| 45 | |||
| 46 | $query = $this->em->createQuery(" |
||
| 47 | SELECT pc |
||
| 48 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
||
| 49 | JOIN pc.player p |
||
| 50 | JOIN p.team t |
||
| 51 | WHERE pc.chart = :chart |
||
| 52 | ORDER BY pc.pointChart DESC"); |
||
| 53 | |||
| 54 | $query->setParameter('chart', $chart); |
||
| 55 | $result = $query->getResult(); |
||
| 56 | |||
| 57 | $list = array(); |
||
| 58 | foreach ($result as $playerChart) { |
||
| 59 | $team = $playerChart->getPlayer()->getTeam(); |
||
| 60 | |||
| 61 | $idTeam = $team->getId(); |
||
| 62 | if (!isset($list[$idTeam])) { |
||
| 63 | $list[$idTeam] = [ |
||
| 64 | 'idTeam' => $playerChart->getPlayer()->getTeam()->getId(), |
||
| 65 | 'nbPlayer' => 1, |
||
| 66 | 'pointChart' => $playerChart->getPointChart(), |
||
| 67 | 'chartRank0' => 0, |
||
| 68 | 'chartRank1' => 0, |
||
| 69 | 'chartRank2' => 0, |
||
| 70 | 'chartRank3' => 0, |
||
| 71 | ]; |
||
| 72 | } elseif ($list[$idTeam]['nbPlayer'] < 5) { |
||
| 73 | $list[$idTeam]['nbPlayer'] += 1; |
||
| 74 | $list[$idTeam]['pointChart'] += $playerChart->getPointChart(); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | //----- add some data |
||
| 79 | $list = array_values($list); |
||
| 80 | $list = Ranking::order($list, ['pointChart' => SORT_DESC]); |
||
| 81 | $list = Ranking::addRank($list, 'rankPointChart', ['pointChart'], true); |
||
| 82 | |||
| 83 | $normalizer = new ObjectNormalizer(); |
||
| 84 | $serializer = new Serializer([$normalizer]); |
||
| 85 | |||
| 86 | $nbTeam = count($list); |
||
| 87 | |||
| 88 | foreach ($list as $row) { |
||
| 89 | //----- add medals |
||
| 90 | if ($row['rankPointChart'] == 1 && $row['nbEqual'] == 1 && $nbTeam > 1) { |
||
| 91 | $row['chartRank0'] = 1; |
||
| 92 | $row['chartRank1'] = 1; |
||
| 93 | } elseif ($row['rankPointChart'] == 1 && $row['nbEqual'] == 1 && $nbTeam == 1) { |
||
| 94 | $row['chartRank1'] = 1; |
||
| 95 | } elseif ($row['rankPointChart'] == 1 && $row['nbEqual'] > 1) { |
||
| 96 | $row['chartRank1'] = 1; |
||
| 97 | } elseif ($row['rankPointChart'] == 2) { |
||
| 98 | $row['chartRank2'] = 1; |
||
| 99 | } elseif ($row['rankPointChart'] == 3) { |
||
| 100 | $row['chartRank3'] = 1; |
||
| 101 | } |
||
| 102 | |||
| 103 | $teamChart = $serializer->denormalize( |
||
| 104 | $row, |
||
| 105 | 'VideoGamesRecords\CoreBundle\Entity\TeamChart' |
||
| 106 | ); |
||
| 107 | $teamChart->setTeam( |
||
| 108 | $this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Team', $row['idTeam']) |
||
| 109 | ); |
||
| 110 | $teamChart->setChart($chart); |
||
| 111 | |||
| 112 | $this->em->persist($teamChart); |
||
| 113 | } |
||
| 114 | |||
| 115 | $this->em->flush(); |
||
| 116 | |||
| 117 | $this->bus->dispatch( |
||
| 118 | new UpdateTeamGroupRank($chart->getGroup()->getId()), |
||
| 119 | [ |
||
| 120 | new DescriptionStamp( |
||
| 121 | sprintf('Update team-ranking for group [%d]', $chart->getGroup()->getId()) |
||
| 122 | ) |
||
| 123 | ] |
||
| 124 | ); |
||
| 125 | return ['success' => true]; |
||
| 126 | } |
||
| 128 |
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