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 |
||
| 9 | class Application extends Container |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | private $middlewares; |
||
| 15 | |||
| 16 | public function __construct(array $config = []) |
||
| 21 | |||
| 22 | public function isCli() |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @return array |
||
| 29 | */ |
||
| 30 | public function getMiddlewares() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param array $middlewares |
||
| 37 | * |
||
| 38 | * @return Application |
||
| 39 | */ |
||
| 40 | public function setMiddlewares(array $middlewares) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Dispatches the request and sends the response |
||
| 49 | * |
||
| 50 | * @param ServerRequestInterface|null $request |
||
| 51 | * |
||
| 52 | * @return $this |
||
| 53 | */ |
||
| 54 | public function execute(ServerRequestInterface $request = null) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Dispatches the request and returns the response |
||
| 65 | * |
||
| 66 | * @param ServerRequestInterface|null $request |
||
| 67 | * |
||
| 68 | * @return ResponseInterface |
||
| 69 | */ |
||
| 70 | public function dispatch(ServerRequestInterface $request = null) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param string|null $key |
||
| 80 | * @param mixed|null $default |
||
| 81 | * |
||
| 82 | * @return Config|mixed |
||
| 83 | */ |
||
| 84 | View Code Duplication | public function config($key = null, $default = null) |
|
| 92 | } |
||
| 93 |
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.