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 | * @var string |
||
47 | */ |
||
48 | public $soapHeaderVersion = Client::HEADER_V4; |
||
49 | |||
50 | /** |
||
51 | * @var AuthParams |
||
52 | */ |
||
53 | public $authParams; |
||
54 | |||
55 | /** |
||
56 | * The default setting for sending messages (if not specified) |
||
57 | * |
||
58 | * Set to FALSE to enable stateless messages - only applies to SOAP header v4 and higher! |
||
59 | * |
||
60 | * @var bool |
||
61 | */ |
||
62 | public $stateful = true; |
||
63 | |||
64 | |||
65 | /** |
||
66 | * @var LoggerInterface |
||
67 | */ |
||
68 | public $logger; |
||
69 | |||
70 | /** |
||
71 | * Override the default \SoapClient options |
||
72 | * |
||
73 | * used when constructing \SoapClient |
||
74 | * |
||
75 | * See Amadeus\Client\Session\Handler\Base::$soapClientOptions for defaults |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | public $soapClientOptions = []; |
||
80 | |||
81 | /** |
||
82 | * Overridden soap client |
||
83 | * |
||
84 | * @var \SoapClient |
||
85 | */ |
||
86 | public $overrideSoapClient; |
||
87 | |||
88 | /** |
||
89 | * @param array $params |
||
90 | */ |
||
91 | public function __construct($params = []) |
||
95 | |||
96 | /** |
||
97 | * Load parameters from an associative array |
||
98 | * |
||
99 | * @param array $params |
||
100 | * @return void |
||
101 | */ |
||
102 | protected function loadFromArray(array $params) { |
||
118 | |||
119 | /** |
||
120 | * Load WSDL from config |
||
121 | * |
||
122 | * @param array $params |
||
123 | * @return void |
||
124 | */ |
||
125 | protected function loadWsdl($params) |
||
129 | |||
130 | /** |
||
131 | * Load Stateful param from config |
||
132 | * |
||
133 | * @param array $params |
||
134 | * @return void |
||
135 | */ |
||
136 | protected function loadStateful($params) |
||
140 | |||
141 | |||
142 | /** |
||
143 | * Load Logger from config |
||
144 | * |
||
145 | * @param array $params |
||
146 | * @return void |
||
147 | */ |
||
148 | protected function loadLogger($params) |
||
154 | |||
155 | /** |
||
156 | * Load Authentication parameters from config |
||
157 | * |
||
158 | * @param array $params |
||
159 | * @return void |
||
160 | */ |
||
161 | protected function loadAuthParams($params) |
||
171 | |||
172 | /** |
||
173 | * Load Override SoapClient parameter from config |
||
174 | * |
||
175 | * @param array $params |
||
176 | * @return void |
||
177 | */ |
||
178 | protected function loadOverrideSoapClient($params) |
||
184 | |||
185 | /** |
||
186 | * Load SoapClient Options from config |
||
187 | * |
||
188 | * @param array $params |
||
189 | * @return void |
||
190 | */ |
||
191 | protected function loadSoapClientOptions($params) |
||
197 | } |
||
198 |
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.