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 |
||
13 | class XMLRPC_Connector { |
||
14 | /** |
||
15 | * The Connection Manager. |
||
16 | * |
||
17 | * @var Manager |
||
18 | */ |
||
19 | private $connection; |
||
20 | |||
21 | /** |
||
22 | * Constructor. |
||
23 | * |
||
24 | * @param Manager $connection The Connection Manager. |
||
25 | */ |
||
26 | public function __construct( Manager $connection ) { |
||
31 | |||
32 | /** |
||
33 | * Attached to the `xmlrpc_methods` filter. |
||
34 | * |
||
35 | * @param array $methods The already registered XML-RPC methods. |
||
36 | * @return array |
||
37 | */ |
||
38 | public function xmlrpc_methods( $methods ) { |
||
46 | |||
47 | /** |
||
48 | * Handles verification that a site is registered. |
||
49 | * |
||
50 | * @param array $registration_data The data sent by the XML-RPC client: |
||
51 | * [ $secret_1, $user_id ]. |
||
52 | * |
||
53 | * @return string|IXR_Error |
||
54 | */ |
||
55 | public function verify_registration( $registration_data ) { |
||
58 | |||
59 | /** |
||
60 | * Normalizes output for XML-RPC. |
||
61 | * |
||
62 | * @param mixed $data The data to output. |
||
63 | */ |
||
64 | private function output( $data ) { |
||
79 | } |
||
80 |