| Conditions | 12 |
| Paths | 9 |
| Total Lines | 78 |
| Code Lines | 46 |
| 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 |
||
| 108 | public function processRecord($login, $score, $checkpoints) |
||
| 109 | { |
||
| 110 | if ($this->isDisabled()) { |
||
| 111 | echo "disabled state.\n"; |
||
| 112 | |||
| 113 | return false; |
||
| 114 | } |
||
| 115 | |||
| 116 | $tempRecords = $this->recordsByLogin; |
||
| 117 | $tempPositions = $this->ranksByLogin; |
||
| 118 | |||
| 119 | if (isset($this->recordsByLogin[$login])) { |
||
| 120 | $record = $this->recordsByLogin[$login]; |
||
| 121 | } else { |
||
| 122 | $record = new DedimaniaRecord($login); |
||
| 123 | $pla = $this->playerStorage->getPlayerInfo($login); |
||
| 124 | $record->nickName = $pla->getNickName(); |
||
| 125 | } |
||
| 126 | |||
| 127 | $tempRecords[$login] = clone $record; |
||
| 128 | $oldRecord = clone $record; |
||
| 129 | |||
| 130 | // if better time |
||
| 131 | if ($score < $oldRecord->best || $oldRecord->best == -1) { |
||
| 132 | $record->best = $score; |
||
| 133 | $record->checks = implode(",", $checkpoints); |
||
| 134 | $tempRecords[$login] = $record; |
||
| 135 | |||
| 136 | // sort and update new rank |
||
| 137 | uasort($tempRecords, [$this, "compare"]); |
||
| 138 | |||
| 139 | if (!isset($this->players[$login])) { |
||
| 140 | echo "player $login not connected\n"; |
||
| 141 | |||
| 142 | return false; |
||
| 143 | } |
||
| 144 | |||
| 145 | $player = $this->players[$login]; |
||
| 146 | |||
| 147 | // recalculate ranks for records |
||
| 148 | $rank = 1; |
||
| 149 | $newRecord = false; |
||
| 150 | foreach ($tempRecords as $key => $tempRecord) { |
||
| 151 | $tempRecords[$key]->rank = $rank; |
||
| 152 | $tempPositions[$key] = $rank; |
||
| 153 | |||
| 154 | if ($tempRecord->login == $login && ($rank <= $this->serverMaxRank || $rank <= $player->maxRank) && $rank < 100) { |
||
| 155 | $newRecord = $tempRecords[$login]; |
||
| 156 | } |
||
| 157 | |||
| 158 | $rank++; |
||
| 159 | } |
||
| 160 | |||
| 161 | |||
| 162 | $tempRecords = array_slice($tempRecords, 0, 100, true); |
||
| 163 | $tempPositions = array_slice($tempPositions, 0, 100, true); |
||
| 164 | |||
| 165 | if ($newRecord) { |
||
| 166 | $this->recordsByLogin = $tempRecords; |
||
| 167 | $outRecords = usort($tempRecords, [$this, 'compare']); |
||
| 168 | |||
| 169 | $this->ranksByLogin = $tempPositions; |
||
|
|
|||
| 170 | $params = [ |
||
| 171 | $newRecord, |
||
| 172 | $oldRecord, |
||
| 173 | $outRecords, |
||
| 174 | $newRecord->rank, |
||
| 175 | $oldRecord->rank, |
||
| 176 | ]; |
||
| 177 | |||
| 178 | $this->dispatcher->dispatch("expansion.dedimania.records.update", [$params]); |
||
| 179 | |||
| 180 | return $newRecord; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | return false; |
||
| 185 | } |
||
| 186 | |||
| 306 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..