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 CheckMethodGroup |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param RequestInterface $request |
||
| 11 | * @param Route $route |
||
| 12 | * @return mixed |
||
| 13 | */ |
||
| 14 | public function __invoke(RequestInterface $request, Route $route) |
||
| 15 | { |
||
| 16 | $supports = $route->getGroup()->getMethods(); |
||
| 17 | if (count($supports) > 0 && !in_array($request->getMethod(), $supports, true)) { |
||
| 18 | return null; |
||
| 19 | } |
||
| 20 | |||
| 21 | return $route($request); |
||
| 22 | } |
||
| 23 | } |
||
| 24 |