| Conditions | 15 |
| Paths | 3097 |
| Total Lines | 135 |
| Code Lines | 56 |
| 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 |
||
| 14 | public function handle($mixed): void |
||
| 15 | { |
||
| 16 | $group = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Group')->find($mixed); |
||
| 17 | if (null === $group) { |
||
| 18 | return; |
||
| 19 | } |
||
| 20 | |||
| 21 | //----- delete |
||
| 22 | $query = $this->em->createQuery('DELETE VideoGamesRecords\CoreBundle\Entity\PlayerGroup pg WHERE pg.group = :group'); |
||
| 23 | $query->setParameter('group', $group); |
||
| 24 | $query->execute(); |
||
| 25 | |||
| 26 | $data = []; |
||
| 27 | |||
| 28 | //----- data rank0 |
||
| 29 | $query = $this->em->createQuery(" |
||
| 30 | SELECT |
||
| 31 | p.id, |
||
| 32 | COUNT(pc.id) as nb |
||
| 33 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
||
| 34 | JOIN pc.player p |
||
| 35 | JOIN pc.chart c |
||
| 36 | WHERE c.group = :group |
||
| 37 | AND pc.rank = 1 |
||
| 38 | AND c.nbPost > 1 |
||
| 39 | AND pc.nbEqual = 1 |
||
| 40 | GROUP BY p.id"); |
||
| 41 | |||
| 42 | |||
| 43 | $query->setParameter('group', $group); |
||
| 44 | $result = $query->getResult(); |
||
| 45 | foreach ($result as $row) { |
||
| 46 | $data['chartRank0'][$row['id']] = $row['nb']; |
||
| 47 | } |
||
| 48 | |||
| 49 | //----- data rank1 to rank5 |
||
| 50 | $query = $this->em->createQuery(" |
||
| 51 | SELECT |
||
| 52 | p.id, |
||
| 53 | COUNT(pc.id) as nb |
||
| 54 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
||
| 55 | JOIN pc.player p |
||
| 56 | JOIN pc.chart c |
||
| 57 | WHERE c.group = :group |
||
| 58 | AND pc.rank = :rank |
||
| 59 | GROUP BY p.id"); |
||
| 60 | $query->setParameter('group', $group); |
||
| 61 | |||
| 62 | for ($i = 1; $i <= 5; $i++) { |
||
| 63 | $query->setParameter('rank', $i); |
||
| 64 | $result = $query->getResult(); |
||
| 65 | foreach ($result as $row) { |
||
| 66 | $data['chartRank' . $i][$row['id']] = $row['nb']; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | //----- data nbRecordProuve |
||
| 71 | $query = $this->em->createQuery(" |
||
| 72 | SELECT |
||
| 73 | p.id, |
||
| 74 | COUNT(pc.id) as nb |
||
| 75 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
||
| 76 | JOIN pc.player p |
||
| 77 | JOIN pc.chart c |
||
| 78 | WHERE c.group = :group |
||
| 79 | AND pc.status = :status |
||
| 80 | GROUP BY p.id"); |
||
| 81 | |||
| 82 | $query->setParameter('group', $group); |
||
| 83 | $query->setParameter( |
||
| 84 | 'status', |
||
| 85 | $this->em->getReference( |
||
| 86 | PlayerChartStatus::class, |
||
| 87 | PlayerChartStatus::ID_STATUS_PROOVED |
||
| 88 | ) |
||
| 89 | ); |
||
| 90 | |||
| 91 | $result = $query->getResult(); |
||
| 92 | foreach ($result as $row) { |
||
| 93 | $data['nbChartProven'][$row['id']] = $row['nb']; |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | //----- select and save result in array |
||
| 98 | $query = $this->em->createQuery(" |
||
| 99 | SELECT |
||
| 100 | p.id, |
||
| 101 | '' as rankPoint, |
||
| 102 | '' as rankMedal, |
||
| 103 | SUM(pc.pointChart) as pointChart, |
||
| 104 | COUNT(pc.id) as nbChart, |
||
| 105 | MAX(pc.lastUpdate) as lastUpdate |
||
| 106 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
||
| 107 | JOIN pc.player p |
||
| 108 | JOIN pc.chart c |
||
| 109 | WHERE c.group = :group |
||
| 110 | GROUP BY p.id |
||
| 111 | ORDER BY pointChart DESC"); |
||
| 112 | |||
| 113 | |||
| 114 | $query->setParameter('group', $group); |
||
| 115 | $result = $query->getResult(); |
||
| 116 | |||
| 117 | $list = []; |
||
| 118 | foreach ($result as $row) { |
||
| 119 | $row['rankMedal'] = 0; |
||
| 120 | $row['chartRank0'] = (isset($data['chartRank0'][$row['id']])) ? $data['chartRank0'][$row['id']] : 0; |
||
| 121 | $row['chartRank1'] = (isset($data['chartRank1'][$row['id']])) ? $data['chartRank1'][$row['id']] : 0; |
||
| 122 | $row['chartRank2'] = (isset($data['chartRank2'][$row['id']])) ? $data['chartRank2'][$row['id']] : 0; |
||
| 123 | $row['chartRank3'] = (isset($data['chartRank3'][$row['id']])) ? $data['chartRank3'][$row['id']] : 0; |
||
| 124 | $row['chartRank4'] = (isset($data['chartRank4'][$row['id']])) ? $data['chartRank4'][$row['id']] : 0; |
||
| 125 | $row['chartRank5'] = (isset($data['chartRank5'][$row['id']])) ? $data['chartRank5'][$row['id']] : 0; |
||
| 126 | $row['nbChartProven'] = (isset($data['nbChartProven'][$row['id']])) ? $data['nbChartProven'][$row['id']] : 0; |
||
| 127 | $row['lastUpdate'] = new DateTime($row['lastUpdate']); |
||
| 128 | $list[] = $row; |
||
| 129 | } |
||
| 130 | |||
| 131 | //----- add some data |
||
| 132 | $list = Ranking::addRank($list, 'rankPointChart', ['pointChart']); |
||
| 133 | $list = Ranking::order($list, ['chartRank0' => SORT_DESC, 'chartRank1' => SORT_DESC, 'chartRank2' => SORT_DESC, 'chartRank3' => SORT_DESC]); |
||
| 134 | $list = Ranking::addRank($list, 'rankMedal', ['chartRank0', 'chartRank1', 'chartRank2', 'chartRank3', 'chartRank4', 'chartRank5']); |
||
| 135 | |||
| 136 | $normalizer = new ObjectNormalizer(); |
||
| 137 | $serializer = new Serializer([$normalizer]); |
||
| 138 | |||
| 139 | foreach ($list as $row) { |
||
| 140 | $playerGroup = $serializer->denormalize( |
||
| 141 | $row, 'VideoGamesRecords\CoreBundle\Entity\PlayerGroup' |
||
| 142 | ); |
||
| 143 | $playerGroup->setPlayer($this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Player', $row['id'])); |
||
| 144 | $playerGroup->setGroup($group); |
||
| 145 | |||
| 146 | $this->em->persist($playerGroup); |
||
| 147 | } |
||
| 148 | $this->em->flush(); |
||
| 149 | } |
||
| 151 |
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