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 |
||
| 15 | class ConsumeContext extends AbstractRabbitMQContext implements Worker |
||
|
|
|||
| 16 | { |
||
| 17 | use LoggerAwareTrait; |
||
| 18 | |||
| 19 | private |
||
| 20 | $consumedMessages; |
||
|
1 ignored issue
–
show
|
|||
| 21 | |||
| 22 | public function __construct($path) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @Given The queue :queue contains the text message :bodyContent |
||
| 32 | */ |
||
| 33 | public function theQueueContainsTheTextMessage($bodyContent, $queue) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @Given The queue :queue contains the json message :bodyContent |
||
| 45 | */ |
||
| 46 | public function theQueueContainsTheJsonMessage($bodyContent, $queue) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @When I consume all the messages in the queue :queue |
||
| 61 | */ |
||
| 62 | public function iConsumeAllTheMessagesInTheQueue($queue) |
||
| 76 | |||
| 77 | public function process(ReadableMessage $message) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @Then /I have consumed (\d+) messages?/ |
||
| 84 | */ |
||
| 85 | public function iHaveConsumedMessage($nbMessages) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @Then the message is a text one |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function theMessageIsATextOne() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @Then the message is a json one |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function theMessageIsAJsonOne() |
|
| 111 | |||
| 112 | /** |
||
| 113 | * @Then the message contains the json :jsonString |
||
| 114 | */ |
||
| 115 | public function theMessageContainsTheJson($jsonString) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @Then the message contains :bodyContent |
||
| 122 | */ |
||
| 123 | public function theMessageContains($bodyContent) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @Then one of the messages is a text one |
||
| 132 | */ |
||
| 133 | public function oneOfTheMessagesIsATextOne() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @Then one of the messages is a json one |
||
| 140 | */ |
||
| 141 | public function oneOfTheMessagesIsAJsonOne() |
||
| 145 | |||
| 146 | private function oneOfTheMessagesIs($contentType, $routingKey) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @Then one of the messages contains the json :jsonString |
||
| 165 | */ |
||
| 166 | public function oneOfTheMessagesContainsTheJson($jsonString) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @Then one of the messages contains :bodyContent |
||
| 173 | */ |
||
| 174 | public function oneOfTheMessagesContains($bodyContent) |
||
| 189 | } |
||
| 190 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.