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 |
||
42 | class WP_HTTP_Proxy { |
||
43 | |||
44 | /** |
||
45 | * Whether proxy connection should be used. |
||
46 | * |
||
47 | * @since 2.8.0 |
||
48 | * |
||
49 | * @use WP_PROXY_HOST |
||
50 | * @use WP_PROXY_PORT |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function is_enabled() { |
||
57 | |||
58 | /** |
||
59 | * Whether authentication should be used. |
||
60 | * |
||
61 | * @since 2.8.0 |
||
62 | * |
||
63 | * @use WP_PROXY_USERNAME |
||
64 | * @use WP_PROXY_PASSWORD |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | public function use_authentication() { |
||
71 | |||
72 | /** |
||
73 | * Retrieve the host for the proxy server. |
||
74 | * |
||
75 | * @since 2.8.0 |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | public function host() { |
||
85 | |||
86 | /** |
||
87 | * Retrieve the port for the proxy server. |
||
88 | * |
||
89 | * @since 2.8.0 |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | public function port() { |
||
99 | |||
100 | /** |
||
101 | * Retrieve the username for proxy authentication. |
||
102 | * |
||
103 | * @since 2.8.0 |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function username() { |
||
113 | |||
114 | /** |
||
115 | * Retrieve the password for proxy authentication. |
||
116 | * |
||
117 | * @since 2.8.0 |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | public function password() { |
||
127 | |||
128 | /** |
||
129 | * Retrieve authentication string for proxy authentication. |
||
130 | * |
||
131 | * @since 2.8.0 |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function authentication() { |
||
138 | |||
139 | /** |
||
140 | * Retrieve header string for proxy authentication. |
||
141 | * |
||
142 | * @since 2.8.0 |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | public function authentication_header() { |
||
149 | |||
150 | /** |
||
151 | * Whether URL should be sent through the proxy server. |
||
152 | * |
||
153 | * We want to keep localhost and the site URL from being sent through the proxy server, because |
||
154 | * some proxies can not handle this. We also have the constant available for defining other |
||
155 | * hosts that won't be sent through the proxy. |
||
156 | * |
||
157 | * @since 2.8.0 |
||
158 | * |
||
159 | * @staticvar array|null $bypass_hosts |
||
160 | * @staticvar array $wildcard_regex |
||
161 | * |
||
162 | * @param string $uri URI to check. |
||
163 | * @return bool True, to send through the proxy and false if, the proxy should not be used. |
||
|
|||
164 | */ |
||
165 | public function send_through_proxy( $uri ) { |
||
219 | } |
||
220 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.