| Total Complexity | 3 |
| Total Lines | 23 |
| Duplicated Lines | 34.78 % |
| Changes | 4 | ||
| Bugs | 2 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 7 | class AJAX extends Controller |
||
| 8 | { |
||
| 9 | public function ranking() |
||
| 10 | { |
||
| 11 | $this->setRank(); |
||
| 12 | |||
| 13 | $rankObj = DB::select('SELECT * FROM users WHERE total_points > 0 ORDER BY total_points DESC,rank;'); |
||
| 14 | $rankArray = json_decode(json_encode($rankObj), true); |
||
| 15 | $userRank = count($rankArray); |
||
| 16 | |||
| 17 | return view('leader.ranking', ['rankArray' => $rankArray, 'userRank' => $userRank]); |
||
| 18 | |||
| 19 | return view('leader.ranking', ['rankArray' => $rankArray, 'userRank' => $userRank])->renderSections()['dynamicRanking']; |
||
|
|
|||
| 20 | } |
||
| 21 | |||
| 22 | View Code Duplication | private function setRank() |
|
| 30 | } |
||
| 31 | } |
||
| 33 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.