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 |
||
| 13 | class SearchEndpointController extends AbstractEndpointController |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Construct |
||
| 17 | * |
||
| 18 | * @param OutfitSearchTransformer $outfitSearchTransformer |
||
| 19 | * @param OutfitTotalRepository $outfitTotalRepo |
||
| 20 | * @param PlayerSearchTransformer $playerSearchTransformer |
||
| 21 | * @param PlayerTotalRepository $playerTotalRepo |
||
| 22 | */ |
||
| 23 | public function __construct( |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Endpoint to return potential players based on search term |
||
| 37 | * |
||
| 38 | * @param ServerRequestInterface $request |
||
| 39 | * @param ResponseInterface $response |
||
| 40 | * @param array $args |
||
| 41 | * |
||
| 42 | * @return ResponseInterface |
||
| 43 | */ |
||
| 44 | public function getPlayersByTerm(ServerRequestInterface $request, ResponseInterface $response, array $args) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Endpoint to return potential players based on search term |
||
| 63 | * |
||
| 64 | * @param ServerRequestInterface $request |
||
| 65 | * @param ResponseInterface $response |
||
| 66 | * @param array $args |
||
| 67 | * |
||
| 68 | * @return ResponseInterface |
||
| 69 | */ |
||
| 70 | public function getOutfitsByTerm(ServerRequestInterface $request, ResponseInterface $response, array $args) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Takes a player name and searches for it |
||
| 89 | * |
||
| 90 | * @param string $term |
||
| 91 | * |
||
| 92 | * @return array |
||
| 93 | */ |
||
| 94 | public function searchForPlayer($term) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Takes a outfit name and searches for it |
||
| 106 | * |
||
| 107 | * @param string $term |
||
| 108 | * |
||
| 109 | * @return array |
||
| 110 | */ |
||
| 111 | public function searchForOutfit($term) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Parses a player name and makes sure it's valid |
||
| 134 | * |
||
| 135 | * @param String $name |
||
| 136 | * |
||
| 137 | * @return ResponseInterface|boolean |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function parsePlayerName($name) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Parses a outfit name and makes sure it's valid |
||
| 154 | * |
||
| 155 | * @param String $name |
||
| 156 | * |
||
| 157 | * @return ResponseInterface|boolean |
||
| 158 | */ |
||
| 159 | View Code Duplication | public function parseOutfitName($name) |
|
| 171 | |||
| 172 | /** |
||
| 173 | * Runs checks on the player ID |
||
| 174 | * |
||
| 175 | * @param string $id |
||
| 176 | * |
||
| 177 | * @return ResponseInterface|boolean |
||
| 178 | */ |
||
| 179 | public function parsePlayerID($id) |
||
| 195 | } |
||
| 196 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.