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 MessageAdapter implements ReadableMessage |
||
| 12 | { |
||
| 13 | private |
||
| 14 | $message, |
||
|
1 ignored issue
–
show
|
|||
| 15 | $decodedBody, |
||
| 16 | $messageHooks; |
||
| 17 | |||
| 18 | public function __construct(\Swarrot\Broker\Message $message) |
||
| 23 | |||
| 24 | public function getRoutingKey() |
||
| 28 | |||
| 29 | public function getContentType() |
||
| 33 | |||
| 34 | public function getAppId() |
||
| 38 | |||
| 39 | public function getHeaders() |
||
| 43 | |||
| 44 | public function getDecodedBody() |
||
| 48 | |||
| 49 | private function decodeBody() |
||
| 61 | |||
| 62 | public function getRawBody() |
||
| 66 | |||
| 67 | public function applyHooks(MessageHookCollection $messageHookCollection) |
||
| 80 | |||
| 81 | public function getFlags() |
||
| 85 | |||
| 86 | public function getAttribute($attributeName) |
||
| 96 | |||
| 97 | private function getFormatterStrategy($contentType) |
||
| 110 | |||
| 111 | public function __toString() |
||
| 119 | |||
| 120 | private function isBinary() |
||
| 124 | |||
| 125 | private function bodyToString() |
||
| 134 | |||
| 135 | public function getService() |
||
| 139 | |||
| 140 | public function getAction() |
||
| 144 | |||
| 145 | public function getAuthor() |
||
| 149 | |||
| 150 | private function getHeader($headerName) |
||
| 160 | |||
| 161 | public function getAttributes() |
||
| 165 | |||
| 166 | public function isLastRetry($retryOccurence = \Puzzle\AMQP\Consumers\Retry::DEFAULT_RETRY_OCCURENCE) |
||
| 172 | |||
| 173 | View Code Duplication | public function getRoutingKeyFromHeader() |
|
| 184 | } |
||
| 185 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.