| Total Complexity | 2 |
| Total Lines | 18 |
| Duplicated Lines | 100 % |
| 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 | View Code Duplication | class RankingController extends Controller |
|
|
|
|||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 11 | */ |
||
| 12 | public function showRanking() |
||
| 13 | { |
||
| 14 | $this->setRank(); |
||
| 15 | |||
| 16 | $rankObj = DB::select('SELECT first_name,scoutname,last_name,rank,total_points,start,end FROM users WHERE total_points > 0 ORDER BY rank DESC, total_points DESC;'); |
||
| 17 | $rankArray = json_decode(json_encode($rankObj), true); |
||
| 18 | $userRank = count($rankArray); |
||
| 19 | |||
| 20 | return view('leader.ranking', ['rankArray' => $rankArray, 'userRank' => $userRank]); |
||
| 21 | } |
||
| 22 | |||
| 23 | private function setRank(){ |
||
| 25 | } |
||
| 26 | } |
||
| 27 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.