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 |
||
| 11 | class URI extends Input |
||
| 12 | { |
||
| 13 | const GUZZLE_HTTP_CONFIG = [ |
||
| 14 | 'allow_redirects' => [ |
||
| 15 | 'max' => self::MAX_REDIRECTS, |
||
| 16 | 'referer' => true, |
||
| 17 | 'strict' => true, |
||
| 18 | ], |
||
| 19 | 'decode_content' => true, |
||
| 20 | 'headers' => [ |
||
| 21 | 'Accept' => 'text/plain;q=1.0, text/*;q=0.8, */*;q=0.1', |
||
| 22 | 'Accept-Charset' => 'utf-8;q=1.0, *;q=0.1', |
||
| 23 | 'Accept-Encoding' => 'identity;q=1.0, *;q=0.1', |
||
| 24 | 'User-Agent' => 'RobotsTxtParser-VIPnytt/2.0 (+https://github.com/VIPnytt/RobotsTxtParser/blob/master/README.md)', |
||
| 25 | ], |
||
| 26 | 'http_errors' => false, |
||
| 27 | 'verify' => true, |
||
| 28 | ]; |
||
| 29 | /** |
||
| 30 | * HTTP Status code |
||
| 31 | * @var int |
||
| 32 | */ |
||
| 33 | protected $statusCode; |
||
| 34 | /** |
||
| 35 | * Parent Client class |
||
| 36 | * @var Input |
||
| 37 | */ |
||
| 38 | private $client; |
||
| 39 | /** |
||
| 40 | * RequestClient timestamp |
||
| 41 | * @var int |
||
| 42 | */ |
||
| 43 | private $time; |
||
| 44 | /** |
||
| 45 | * Cache-Control max-age |
||
| 46 | * @var int |
||
| 47 | */ |
||
| 48 | private $maxAge; |
||
| 49 | /** |
||
| 50 | * Robots.txt contents |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $contents; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Robots.txt character encoding |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $encoding; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * RequestClient constructor. |
||
| 63 | * |
||
| 64 | * @param string $baseUri |
||
| 65 | * @param array $guzzleConfig |
||
| 66 | * @param int|null $byteLimit |
||
| 67 | */ |
||
| 68 | public function __construct($baseUri, array $guzzleConfig = [], $byteLimit = self::BYTE_LIMIT) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Content-Type encoding HTTP header |
||
| 98 | * |
||
| 99 | * @param array $headers |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | private function headerEncoding(array $headers) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Client header |
||
| 112 | * |
||
| 113 | * @param array $headers |
||
| 114 | * @param string $part |
||
| 115 | * @param string $delimiter |
||
| 116 | * @return string|false |
||
| 117 | */ |
||
| 118 | private function parseHeader(array $headers, $part, $delimiter = ";") |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Cache-Control max-age HTTP header |
||
| 133 | * |
||
| 134 | * @param array $headers |
||
| 135 | * @return int |
||
| 136 | */ |
||
| 137 | private function headerMaxAge(array $headers) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Base URI |
||
| 147 | * |
||
| 148 | * @return string |
||
| 149 | */ |
||
| 150 | public function getBaseUri() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Status code |
||
| 157 | * |
||
| 158 | * @return int |
||
| 159 | */ |
||
| 160 | public function getStatusCode() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * URL content |
||
| 167 | * |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | public function getContents() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Encoding |
||
| 177 | * |
||
| 178 | * @return string |
||
| 179 | */ |
||
| 180 | public function getEncoding() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Next update timestamp |
||
| 187 | * |
||
| 188 | * @return int |
||
| 189 | */ |
||
| 190 | public function nextUpdate() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Valid until timestamp |
||
| 197 | * |
||
| 198 | * @return int |
||
| 199 | */ |
||
| 200 | public function validUntil() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Client class |
||
| 207 | * |
||
| 208 | * @return Input |
||
| 209 | */ |
||
| 210 | public function getClientClass() |
||
| 214 | } |
||
| 215 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.