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 |
||
| 18 | class ConfiguredClientsStrategy implements DiscoveryStrategy, EventSubscriberInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var HttpClient |
||
| 22 | */ |
||
| 23 | private static $client; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var HttpAsyncClient |
||
| 27 | */ |
||
| 28 | private static $asyncClient; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param HttpClient $httpClient |
||
| 32 | * @param HttpAsyncClient $asyncClient |
||
| 33 | */ |
||
| 34 | 17 | public function __construct(HttpClient $httpClient = null, HttpAsyncClient $asyncClient = null) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritdoc} |
||
| 43 | */ |
||
| 44 | public static function getCandidates($type) |
||
| 45 | { |
||
| 46 | if (HttpClient::class === $type && null !== self::$client) { |
||
| 47 | return [['class' => function () { |
||
| 48 | return self::$client; |
||
| 49 | }]]; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (HttpAsyncClient::class === $type && null !== self::$asyncClient) { |
||
| 53 | return [['class' => function () { |
||
| 54 | return self::$asyncClient; |
||
| 55 | }]]; |
||
| 56 | } |
||
| 57 | |||
| 58 | 14 | return []; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Make sure to use our custom strategy. |
||
| 63 | * |
||
| 64 | * @param Event $e |
||
| 65 | */ |
||
| 66 | public function onEvent(Event $e) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Whenever these events occur we make sure to add our strategy to the discovery. |
||
| 73 | * |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | View Code Duplication | public static function getSubscribedEvents() |
|
| 83 | } |
||
| 84 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.