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 |
||
| 33 | class SoapHeader2 extends Base |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * Namespace of SoapHeader V2 |
||
| 37 | */ |
||
| 38 | const CORE_WS_V2_SESSION_NS = 'http://xml.amadeus.com/ws/2009/01/WBS_Session-2.0.xsd'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Node for Session |
||
| 42 | */ |
||
| 43 | const NODENAME_SESSION = "Session"; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Node for Session ID |
||
| 47 | */ |
||
| 48 | const NODENAME_SESSIONID = "SessionId"; |
||
| 49 | /** |
||
| 50 | * Node for Session Sequence Number |
||
| 51 | */ |
||
| 52 | const NODENAME_SEQENCENR = "SequenceNumber"; |
||
| 53 | /** |
||
| 54 | * Node for Session Security Token |
||
| 55 | */ |
||
| 56 | const NODENAME_SECURITYTOKEN = "SecurityToken"; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Prepare to send a next message and checks if authenticated |
||
| 60 | * |
||
| 61 | * @param string $messageName |
||
| 62 | * @param array $messageOptions |
||
| 63 | * @throws InvalidSessionException When trying to send a message without session. |
||
| 64 | */ |
||
| 65 | 12 | protected function prepareForNextMessage($messageName, $messageOptions) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Handles post message actions |
||
| 90 | * |
||
| 91 | * Handles session state based on received response |
||
| 92 | * |
||
| 93 | * @param string $messageName |
||
| 94 | * @param string $lastResponse |
||
| 95 | * @param array $messageOptions |
||
| 96 | * @param mixed $result |
||
| 97 | */ |
||
| 98 | 8 | protected function handlePostMessage($messageName, $lastResponse, $messageOptions, $result) |
|
| 107 | |||
| 108 | /** |
||
| 109 | * @param string $responseMsg the full response XML received. |
||
| 110 | * @return array |
||
| 111 | */ |
||
| 112 | 4 | protected function getSessionDataFromHeader($responseMsg) |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Cannot set stateless on Soap Header v2 |
||
| 145 | * |
||
| 146 | * @param bool $stateful |
||
| 147 | * @throws UnsupportedOperationException |
||
| 148 | */ |
||
| 149 | 52 | public function setStateful($stateful) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Soap Header 2 sessions are always stateful |
||
| 158 | * |
||
| 159 | * @return bool |
||
| 160 | */ |
||
| 161 | 4 | public function isStateful() |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Is the TransactionFlowLink header enabled? |
||
| 168 | * |
||
| 169 | * @return bool |
||
| 170 | */ |
||
| 171 | 4 | public function isTransactionFlowLinkEnabled() |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Enable or disable TransactionFlowLink header |
||
| 178 | * |
||
| 179 | * @throws UnsupportedOperationException when used on unsupported WSAP versions |
||
| 180 | * @param bool $enabled |
||
| 181 | */ |
||
| 182 | 52 | public function setTransactionFlowLink($enabled) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Get the TransactionFlowLink Consumer ID |
||
| 191 | * |
||
| 192 | * @return string|null |
||
| 193 | */ |
||
| 194 | 4 | public function getConsumerId() |
|
| 198 | |||
| 199 | /** |
||
| 200 | * Set the TransactionFlowLink Consumer ID |
||
| 201 | * |
||
| 202 | * @throws UnsupportedOperationException when used on unsupported WSAP versions |
||
| 203 | * @param string $id |
||
| 204 | * @return void |
||
| 205 | */ |
||
| 206 | 52 | public function setConsumerId($id) |
|
| 212 | |||
| 213 | |||
| 214 | /** |
||
| 215 | * Make SoapClient options for Soap Header 2 handler |
||
| 216 | * |
||
| 217 | * @return array |
||
| 218 | */ |
||
| 219 | 8 | View Code Duplication | protected function makeSoapClientOptions() |
| 230 | } |
||
| 231 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.