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 |
||
32 | class SoapRequestDataHolder extends WebserviceRequestDataHolder implements HeadersRequestDataHolderInterface |
||
33 | { |
||
34 | /** |
||
35 | * @constant Constant for source name of HTTP headers. |
||
36 | */ |
||
37 | const SOURCE_HEADERS = 'headers'; |
||
38 | |||
39 | /** |
||
40 | * @var array An array of headers sent with the request. |
||
41 | */ |
||
42 | protected $headers = array(); |
||
43 | |||
44 | /** |
||
45 | * Constructor |
||
46 | * |
||
47 | * @param array $data An associative array of request data source names and |
||
48 | * data arrays. |
||
49 | * |
||
50 | * @author David Zülke <[email protected]> |
||
51 | * @since 0.11.0 |
||
52 | */ |
||
53 | public function __construct(array $data = array()) |
||
61 | |||
62 | /** |
||
63 | * Clear all headers. |
||
64 | * |
||
65 | * @author Dominik del Bondio <[email protected]> |
||
66 | * @since 0.11.0 |
||
67 | */ |
||
68 | public function clearHeaders() |
||
72 | |||
73 | /** |
||
74 | * Retrieve all HTTP headers. |
||
75 | * |
||
76 | * @return array A list of SOAP headers. |
||
77 | * |
||
78 | * @author David Zülke <[email protected]> |
||
79 | * @since 0.11.0 |
||
80 | */ |
||
81 | public function &getHeaders() |
||
85 | |||
86 | /** |
||
87 | * Get a HTTP header. |
||
88 | * |
||
89 | * @param string $name Case-insensitive name of a header, using either a hyphen |
||
90 | * or an underscore as a separator. |
||
91 | * @param mixed $defualt A default value. |
||
|
|||
92 | * |
||
93 | * @return string The header value, or null if header wasn't set. |
||
94 | * |
||
95 | * @author David Zülke <[email protected]> |
||
96 | * @since 0.11.0 |
||
97 | */ |
||
98 | public function &getHeader($name, $default = null) |
||
106 | |||
107 | /** |
||
108 | * Check if a HTTP header exists. |
||
109 | * |
||
110 | * @param string $name Case-insensitive name of a header, using either a hyphen |
||
111 | * or an underscore as a separator. |
||
112 | * |
||
113 | * @return bool True if the header was sent with the current request. |
||
114 | * |
||
115 | * @author David Zülke <[email protected]> |
||
116 | * @since 0.11.0 |
||
117 | */ |
||
118 | public function hasHeader($name) |
||
122 | |||
123 | /** |
||
124 | * Checks if there is a value of a header is empty or not set. |
||
125 | * |
||
126 | * @param string $name The header name. |
||
127 | * |
||
128 | * @return bool The result. |
||
129 | * |
||
130 | * @author David Zülke <[email protected]> |
||
131 | * @since 0.11.0 |
||
132 | */ |
||
133 | public function isHeaderValueEmpty($name) |
||
137 | /** |
||
138 | * Set a header. |
||
139 | * |
||
140 | * The header name is normalized before storing it. |
||
141 | * |
||
142 | * @param string $name A header name. |
||
143 | * @param mixed $value A header value. |
||
144 | * |
||
145 | * @author David Zülke <[email protected]> |
||
146 | * @since 0.11.0 |
||
147 | */ |
||
148 | public function setHeader($name, $value) |
||
152 | |||
153 | /** |
||
154 | * Set an array of headers. |
||
155 | * |
||
156 | * @param array $headers An associative array of headers and their values. |
||
157 | * |
||
158 | * @author Dominik del Bondio <[email protected]> |
||
159 | * @since 0.11.0 |
||
160 | */ |
||
161 | public function setHeaders(array $headers) |
||
165 | |||
166 | /** |
||
167 | * Remove a HTTP header. |
||
168 | * |
||
169 | * @param string $name Case-insensitive name of a header, using either a hyphen |
||
170 | * or an underscore as a separator. |
||
171 | * |
||
172 | * @return string The value of the removed header, if it had been set. |
||
173 | * |
||
174 | * @author David Zülke <[email protected]> |
||
175 | * @since 0.11.0 |
||
176 | */ |
||
177 | public function &removeHeader($name) |
||
186 | |||
187 | /** |
||
188 | * Retrieve an array of header names. |
||
189 | * |
||
190 | * @return array An indexed array of header names in original PHP format. |
||
191 | * |
||
192 | * @author David Zülke <[email protected]> |
||
193 | * @since 0.11.0 |
||
194 | */ |
||
195 | public function getHeaderNames() |
||
199 | |||
200 | /** |
||
201 | * Merge in Headers from another request data holder. |
||
202 | * |
||
203 | * @param RequestDataHolder $other The other request data holder. |
||
204 | * |
||
205 | * @author David Zülke <[email protected]> |
||
206 | * @since 0.11.0 |
||
207 | */ |
||
208 | public function mergeHeaders(RequestDataHolder $other) |
||
214 | } |
||
215 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.