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 |
||
| 13 | class NewGoogleSearchMiddleware implements MiddlewareInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var GoogleSearch |
||
| 17 | */ |
||
| 18 | private $search; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * GoogleSearchMiddleware constructor. |
||
| 22 | * |
||
| 23 | * @param Repository $config |
||
| 24 | */ |
||
| 25 | public function __construct(Repository $config) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Message $message |
||
| 32 | * |
||
| 33 | * @return array |
||
| 34 | */ |
||
| 35 | public function handle(Message $message) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param Message $message |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | private function getGoogleQuery(Message $message) : string |
||
| 85 | } |
||
| 86 |