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 LaravelGenerator extends AbstractGenerator |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @param Route $route |
||
14 | * @return mixed |
||
15 | */ |
||
16 | protected function getUri(Route $route) |
||
20 | |||
21 | /** |
||
22 | * @param \Illuminate\Routing\Route $route |
||
23 | * @param array $bindings |
||
24 | * |
||
25 | * @return array |
||
26 | */ |
||
27 | View Code Duplication | public function processRoute(Route $route, $bindings = []) |
|
51 | |||
52 | /** |
||
53 | * Call the given URI and return the Response. |
||
54 | * |
||
55 | * @param string $method |
||
56 | * @param string $uri |
||
57 | * @param array $parameters |
||
58 | * @param array $cookies |
||
59 | * @param array $files |
||
60 | * @param array $server |
||
61 | * @param string $content |
||
62 | * |
||
63 | * @return \Illuminate\Http\Response |
||
64 | */ |
||
65 | public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) |
||
86 | |||
87 | } |
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.