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 |
||
| 34 | class SessionHandlerParams |
||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Full file & path to the WSDL file to be used |
||
| 39 | * |
||
| 40 | * @var string[] |
||
| 41 | */ |
||
| 42 | public $wsdl = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Which Soap Header version to be used |
||
| 46 | * |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | public $soapHeaderVersion = Client::HEADER_V4; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var AuthParams |
||
| 53 | */ |
||
| 54 | public $authParams; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The default setting for sending messages (if not specified) |
||
| 58 | * |
||
| 59 | * Set to FALSE to enable stateless messages - only applies to SOAP header v4 and higher! |
||
| 60 | * |
||
| 61 | * @var bool |
||
| 62 | */ |
||
| 63 | public $stateful = true; |
||
| 64 | |||
| 65 | |||
| 66 | /** |
||
| 67 | * @var LoggerInterface |
||
| 68 | */ |
||
| 69 | public $logger; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Override the default \SoapClient options |
||
| 73 | * |
||
| 74 | * used when constructing \SoapClient |
||
| 75 | * |
||
| 76 | * See Amadeus\Client\Session\Handler\Base::$soapClientOptions for defaults |
||
| 77 | * |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | public $soapClientOptions = []; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Overridden soap client |
||
| 84 | * |
||
| 85 | * @var \SoapClient |
||
| 86 | */ |
||
| 87 | public $overrideSoapClient; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Override SoapClient WSDL name |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | public $overrideSoapClientWsdlName; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Enable the TransactionFlowLink SOAP Header? |
||
| 98 | * |
||
| 99 | * @var bool |
||
| 100 | */ |
||
| 101 | public $enableTransactionFlowLink = false; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Consumer ID for Transaction Flow Link |
||
| 105 | * |
||
| 106 | * @var string|null |
||
| 107 | */ |
||
| 108 | public $consumerId = null; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param array $params |
||
| 112 | */ |
||
| 113 | 288 | public function __construct($params = []) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Load parameters from an associative array |
||
| 120 | * |
||
| 121 | * @param array $params |
||
| 122 | * @return void |
||
| 123 | */ |
||
| 124 | 288 | protected function loadFromArray(array $params) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Load WSDL from config |
||
| 146 | * |
||
| 147 | * Either a single WSDL location as string or a list of WSDL locations as array. |
||
| 148 | * |
||
| 149 | * @param array $params |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | 280 | View Code Duplication | protected function loadWsdl($params) |
| 164 | |||
| 165 | /** |
||
| 166 | * Load Stateful param from config |
||
| 167 | * |
||
| 168 | * @param array $params |
||
| 169 | * @return void |
||
| 170 | */ |
||
| 171 | 280 | protected function loadStateful($params) |
|
| 175 | |||
| 176 | |||
| 177 | /** |
||
| 178 | * Load Logger from config |
||
| 179 | * |
||
| 180 | * @param array $params |
||
| 181 | * @return void |
||
| 182 | */ |
||
| 183 | 280 | protected function loadLogger($params) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Load Authentication parameters from config |
||
| 192 | * |
||
| 193 | * @param array $params |
||
| 194 | * @return void |
||
| 195 | */ |
||
| 196 | 280 | View Code Duplication | protected function loadAuthParams($params) |
| 206 | |||
| 207 | /** |
||
| 208 | * Load Override SoapClient parameter from config |
||
| 209 | * |
||
| 210 | * @param array $params |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | 280 | protected function loadOverrideSoapClient($params) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Load SoapClient Options from config |
||
| 225 | * |
||
| 226 | * @param array $params |
||
| 227 | * @return void |
||
| 228 | */ |
||
| 229 | 280 | protected function loadSoapClientOptions($params) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * Load TransactionFlowLink options from config |
||
| 238 | * |
||
| 239 | * @param array $params |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | 280 | protected function loadTransactionFlowLink($params) |
|
| 249 | } |
||
| 250 |
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.