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 |
||
| 19 | class PhpVarsCheckRouter implements MiddlewareInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * The logger used by Splash. |
||
| 23 | * |
||
| 24 | * @var LoggerInterface |
||
| 25 | */ |
||
| 26 | private $log; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * A simple counter to check requests' length (GET, POST, REQUEST). |
||
| 30 | * |
||
| 31 | * @var int |
||
| 32 | */ |
||
| 33 | private $count; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @Important |
||
| 37 | * |
||
| 38 | * @param LoggerInterface $log The logger used by Splash |
||
| 39 | */ |
||
| 40 | public function __construct(LoggerInterface $log = null) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Get the min in 2 values if there exist. |
||
| 47 | * |
||
| 48 | * @param int $val1 |
||
| 49 | * @param int $val2 |
||
| 50 | * |
||
| 51 | * @return int|NULL |
||
| 52 | */ |
||
| 53 | private function getMinInConfiguration($val1, $val2) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Returns the number of bytes from php.ini parameter. |
||
| 70 | * |
||
| 71 | * @param $val |
||
| 72 | * |
||
| 73 | * @return int|string |
||
| 74 | */ |
||
| 75 | private static function iniGetBytes($val) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Count number of element in array. |
||
| 100 | * |
||
| 101 | * @param mixed $item |
||
| 102 | * @param mixed $key |
||
| 103 | */ |
||
| 104 | private function countRecursive($item, $key) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Process an incoming request and/or response. |
||
| 111 | * |
||
| 112 | * Accepts a server-side request and a response instance, and does |
||
| 113 | * something with them. |
||
| 114 | * |
||
| 115 | * If the response is not complete and/or further processing would not |
||
| 116 | * interfere with the work done in the middleware, or if the middleware |
||
| 117 | * wants to delegate to another process, it can use the `$out` callable |
||
| 118 | * if present. |
||
| 119 | * |
||
| 120 | * If the middleware does not return a value, execution of the current |
||
| 121 | * request is considered complete, and the response instance provided will |
||
| 122 | * be considered the response to return. |
||
| 123 | * |
||
| 124 | * Alternately, the middleware may return a response instance. |
||
| 125 | * |
||
| 126 | * Often, middleware will `return $out();`, with the assumption that a |
||
| 127 | * later middleware will return a response. |
||
| 128 | * |
||
| 129 | * @param Request $request |
||
| 130 | * @param Response $response |
||
| 131 | * @param null|callable $out |
||
| 132 | * |
||
| 133 | * @return null|Response |
||
| 134 | * |
||
| 135 | * @throws SplashException |
||
| 136 | */ |
||
| 137 | public function __invoke(Request $request, Response $response, callable $out = null) |
||
| 198 | } |
||
| 199 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.