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 SoapHeader4 extends Base |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * XPATH query to retrieve the SOAPAction from the WSDL for a given message. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | const XPATH_OPERATION_ACTION = 'string(//wsdl:operation[./@name="%s"]/soap:operation/@soapAction)'; |
||
| 41 | /** |
||
| 42 | * XPATH query to retrieve the server endpoint from the WSDL. |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | const XPATH_ENDPOINT = 'string(/wsdl:definitions/wsdl:service/wsdl:port/soap:address/@location)'; |
||
| 47 | |||
| 48 | |||
| 49 | /** |
||
| 50 | * Switch between stateful & stateless sessions. Default: stateful |
||
| 51 | * |
||
| 52 | * @var bool |
||
| 53 | */ |
||
| 54 | protected $isStateful = true; |
||
| 55 | |||
| 56 | protected $enableTransactionFlowLink = false; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * TransactionFlowLink Consumer ID |
||
| 60 | * |
||
| 61 | * @var string|null |
||
| 62 | */ |
||
| 63 | protected $consumerId; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param bool $stateful |
||
| 67 | */ |
||
| 68 | 184 | public function setStateful($stateful) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Check whether we are running in stateful mode (true) or in stateless mode (false) |
||
| 75 | * |
||
| 76 | * @return bool |
||
| 77 | */ |
||
| 78 | 76 | public function isStateful() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Is the TransactionFlowLink header enabled? |
||
| 85 | * |
||
| 86 | * @return bool |
||
| 87 | */ |
||
| 88 | 52 | public function isTransactionFlowLinkEnabled() |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Enable or disable TransactionFlowLink header |
||
| 95 | * |
||
| 96 | * @param bool $enabled |
||
| 97 | */ |
||
| 98 | 184 | public function setTransactionFlowLink($enabled) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Get the TransactionFlowLink Consumer ID |
||
| 105 | * |
||
| 106 | * @param bool $generate Whether to generate a consumer ID |
||
| 107 | * @return string|null |
||
| 108 | */ |
||
| 109 | 12 | public function getConsumerId($generate = false) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Set the TransactionFlowLink Consumer ID |
||
| 120 | * |
||
| 121 | * @param string $id |
||
| 122 | * @return void |
||
| 123 | */ |
||
| 124 | 184 | public function setConsumerId($id) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Handles authentication & sessions |
||
| 131 | * |
||
| 132 | * If authenticated, increment sequence number for next message and set session info to soapheader |
||
| 133 | * If not, set auth info to soapheader |
||
| 134 | * |
||
| 135 | * @uses $this->isAuthenticated |
||
| 136 | * @uses $this->sessionData |
||
| 137 | * @param string $messageName |
||
| 138 | * @param array $messageOptions |
||
| 139 | */ |
||
| 140 | 32 | protected function prepareForNextMessage($messageName, $messageOptions) |
|
| 151 | |||
| 152 | |||
| 153 | /** |
||
| 154 | * Handles post message actions |
||
| 155 | * |
||
| 156 | * - look for session info and set status variables |
||
| 157 | * - checks for message errors? |
||
| 158 | * - ends terminated sessions |
||
| 159 | * |
||
| 160 | * @param string $messageName |
||
| 161 | * @param string $lastResponse |
||
| 162 | * @param array $messageOptions |
||
| 163 | * @param mixed $result |
||
| 164 | * @return void |
||
| 165 | */ |
||
| 166 | 32 | protected function handlePostMessage($messageName, $lastResponse, $messageOptions, $result) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @param string $responseMsg the full response XML received. |
||
| 182 | * @return array |
||
| 183 | */ |
||
| 184 | 20 | protected function getSessionDataFromHeader($responseMsg) |
|
| 218 | |||
| 219 | /** |
||
| 220 | * Create the Soap Headers to be used on the subsequent request. |
||
| 221 | * |
||
| 222 | * This depends on the current Session Data (if there is an active session) and |
||
| 223 | * the Session Handler parameters (to create a new or stateless session) |
||
| 224 | * |
||
| 225 | * You can also terminate the session with $doEndSession = true |
||
| 226 | * |
||
| 227 | * @param array $sessionData |
||
| 228 | * @param Client\Params\SessionHandlerParams $params |
||
| 229 | * @param string $messageName |
||
| 230 | * @param array $messageOptions |
||
| 231 | * @return \SoapHeader[]|null |
||
|
|
|||
| 232 | */ |
||
| 233 | 52 | protected function createSoapHeaders($sessionData, $params, $messageName, $messageOptions) |
|
| 367 | |||
| 368 | /** |
||
| 369 | * Get the Web Services server Endpoint from the WSDL. |
||
| 370 | * |
||
| 371 | * @param string $wsdlFilePath |
||
| 372 | * @param string $messageName |
||
| 373 | * @return string|null |
||
| 374 | */ |
||
| 375 | 52 | protected function getEndpointFromWsdl($wsdlFilePath, $messageName) |
|
| 385 | |||
| 386 | /** |
||
| 387 | * Get the SOAPAction for a given message from the WSDL contents. |
||
| 388 | * |
||
| 389 | * @param string $wsdlFilePath |
||
| 390 | * @param string $messageName |
||
| 391 | * @return string|null |
||
| 392 | */ |
||
| 393 | 52 | protected function getActionFromWsdl($wsdlFilePath, $messageName) |
|
| 403 | |||
| 404 | /** |
||
| 405 | * Generate a GUID |
||
| 406 | * |
||
| 407 | * @return string |
||
| 408 | */ |
||
| 409 | 52 | protected function generateGuid() |
|
| 423 | |||
| 424 | /** |
||
| 425 | * @param string $originator |
||
| 426 | * @param string $nonce |
||
| 427 | * @param string $pwDigest |
||
| 428 | * @param string $creationTimeString |
||
| 429 | * @return string |
||
| 430 | */ |
||
| 431 | 48 | protected function generateSecurityHeaderRawXml($originator, $nonce, $pwDigest, $creationTimeString) |
|
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * @param string $nonceBase |
||
| 446 | * @param string $creationString |
||
| 447 | * @return string |
||
| 448 | */ |
||
| 449 | 44 | protected function generateUniqueNonce($nonceBase, $creationString) |
|
| 460 | |||
| 461 | /** |
||
| 462 | * Generates a Password Digest following this algorithm: |
||
| 463 | * HashedPassword = Base64(SHA-1( nonce + created + SHA-1 ( password ))) |
||
| 464 | * as defined in |
||
| 465 | * https://webservices.amadeus.com/extranet/kdbViewDocument.do?externalId=wikidoc_web_services_embedded_security_implementation_guide_header_entries_ws-security_usernametoken&docStatus=Published&mpId=fla__1__technical |
||
| 466 | * |
||
| 467 | * EXAMPLE: with: |
||
| 468 | * Nonce in Base 64 = 'PZgFvh5439plJpKpIyf5ucmXhNU=' |
||
| 469 | * Timestamp = '2013-01-11T09:41:03Z' |
||
| 470 | * Clear Password = 'WBSPassword' |
||
| 471 | * The digest algorithm returns the Encrypted Password in Base 64: |
||
| 472 | * HshPwd = 'ic3AOJElVpvkz9ZBKd105Siry28=' |
||
| 473 | * |
||
| 474 | * @param string $password CLEARTEXT password (NOT the base64 encoded password used in Security_Authenticate) |
||
| 475 | * @param string $creationString message creation datetime |
||
| 476 | * UTC Format: yyyy-mm-ddTHH:MM:SSZ or yyyy-mm-ddTHH:MM:SS.sssZ |
||
| 477 | * @param string $messageNonce Random unique string |
||
| 478 | * @return string The generated Password Digest |
||
| 479 | */ |
||
| 480 | 68 | protected function generatePasswordDigest($password, $creationString, $messageNonce) |
|
| 484 | |||
| 485 | /** |
||
| 486 | * @param \DateTime $creationDateTime |
||
| 487 | * @param string $micro |
||
| 488 | * @return string |
||
| 489 | */ |
||
| 490 | 44 | protected function createDateTimeStringForAuth($creationDateTime, $micro) |
|
| 495 | |||
| 496 | /** |
||
| 497 | * Make SoapClient options for Soap Header 4 handler |
||
| 498 | * |
||
| 499 | * @return array |
||
| 500 | */ |
||
| 501 | 8 | View Code Duplication | protected function makeSoapClientOptions() |
| 512 | } |
||
| 513 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.