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 |
||
33 | class RSymfonyAdaptor extends AbstractAdaptor |
||
34 | { |
||
35 | protected $locator; |
||
36 | protected $context; |
||
37 | |||
38 | protected $defaults = [ |
||
39 | 'cacheDisabled' => true, |
||
40 | 'cacheFile' => __DIR__ . 'r.cache', |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * FastRouteAdaptor constructor. |
||
45 | * |
||
46 | * @param SerializerInterface $serializer |
||
47 | * @param array $options |
||
48 | * @throws RouterException |
||
49 | */ |
||
50 | public function __construct(SerializerInterface $serializer, array $options = []) |
||
56 | |||
57 | /** |
||
58 | * Return RouterResponse for given route. |
||
59 | * |
||
60 | * @param RouteCollectionInterface $routes |
||
61 | * @param string $method |
||
62 | * @param string $requestTarget |
||
63 | * @return RouterResponse |
||
64 | * @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException |
||
65 | * @throws \Symfony\Component\Routing\Exception\MethodNotAllowedException |
||
66 | */ |
||
67 | View Code Duplication | public function match(RouteCollectionInterface $routes, $method, $requestTarget) |
|
85 | |||
86 | public function getSymfonyRouteCollection(RouteCollectionInterface $routes) |
||
124 | |||
125 | /** |
||
126 | * Unserialize any cached content and return RouterResponse. |
||
127 | * |
||
128 | * @param $dispatchResponse |
||
129 | * @return RouterResponse |
||
130 | */ |
||
131 | View Code Duplication | public function createRouterResponse($dispatchResponse) |
|
147 | |||
148 | public function createFastRouteHandler(RouteInterface $route) |
||
163 | |||
164 | /** |
||
165 | * Check if Cache Enabled and whether too skip adding routes. |
||
166 | * |
||
167 | * @return boolean |
||
168 | */ |
||
169 | public function isCached() |
||
173 | |||
174 | /** |
||
175 | * @inheritdoc |
||
176 | */ |
||
177 | public function getCachedRoutes($context = '') |
||
181 | } |
||
182 |
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.