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 Paystack |
||
| 8 | { |
||
| 9 | |||
| 10 | public $secret_key; |
||
| 11 | private $routes; |
||
| 12 | public $use_guzzle = false; |
||
| 13 | |||
| 14 | 4 | public function __construct($secret_key) |
|
| 23 | |||
| 24 | public function useGuzzle() |
||
| 28 | |||
| 29 | 3 | private function definedRoutes() |
|
| 40 | |||
| 41 | /** |
||
| 42 | * __call |
||
| 43 | * Magic Method for fetch on routes |
||
| 44 | * |
||
| 45 | * @param $method - a string whose title case is a class in the |
||
| 46 | * Yabacon\Paystack\Routes namespace implementing |
||
| 47 | * Yabacon\Paystack\Contracts\RouteInterface |
||
| 48 | * @param $args - arguments sent to the magic method |
||
| 49 | * |
||
| 50 | * @return the result of calling /{route}/get on the api |
||
| 51 | * |
||
| 52 | * @access public |
||
| 53 | * @see Yabacon\Paystack\Routes\Router |
||
| 54 | * @since 1.0 |
||
| 55 | */ |
||
| 56 | public function __call($method, $args) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @deprecated |
||
| 91 | */ |
||
| 92 | public static function registerAutoloader() |
||
| 103 | |||
| 104 | /** |
||
| 105 | * __get |
||
| 106 | * Magic method to create a new Router |
||
| 107 | * which performs all actions required |
||
| 108 | */ |
||
| 109 | public function __get($name) |
||
| 115 | } |
||
| 116 |
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.