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  | 
            ||
| 10 | trait ItFetchesServers  | 
            ||
| 11 | { | 
            ||
| 12 | /**  | 
            ||
| 13 | * Fetch servers  | 
            ||
| 14 | */  | 
            ||
| 15 | View Code Duplication | protected function fetchServers()  | 
            |
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * Get forge id server from server name.  | 
            ||
| 36 | *  | 
            ||
| 37 | * @param $servers  | 
            ||
| 38 | * @param $server_name  | 
            ||
| 39 | * @return mixed  | 
            ||
| 40 | */  | 
            ||
| 41 | protected function getForgeIdServer($servers, $server_name)  | 
            ||
| 46 | |||
| 47 | /**  | 
            ||
| 48 | * Get forge name from forge id.  | 
            ||
| 49 | *  | 
            ||
| 50 | * @param $servers  | 
            ||
| 51 | * @param $server_id  | 
            ||
| 52 | * @return mixed  | 
            ||
| 53 | */  | 
            ||
| 54 | protected function getForgeName($servers, $server_id)  | 
            ||
| 59 | |||
| 60 | /**  | 
            ||
| 61 | * Get server ip addres by forge server id.  | 
            ||
| 62 | *  | 
            ||
| 63 | * @param $servers  | 
            ||
| 64 | * @param $server_id  | 
            ||
| 65 | * @return mixed  | 
            ||
| 66 | */  | 
            ||
| 67 | protected function serverIpAddress($servers, $server_id)  | 
            ||
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * Search server by property with a specific value.  | 
            ||
| 75 | *  | 
            ||
| 76 | * @param $servers  | 
            ||
| 77 | * @param $property  | 
            ||
| 78 | * @param $value  | 
            ||
| 79 | * @return static  | 
            ||
| 80 | */  | 
            ||
| 81 | protected function searchServer($servers, $property, $value)  | 
            ||
| 87 | }  | 
            ||
| 88 | 
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.