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 |
||
| 24 | class XMLRPC_Async_Call { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Hold the IXR Clients that will be dispatched at shutdown |
||
| 28 | * |
||
| 29 | * Clients are stored in the following schema: |
||
| 30 | * [ |
||
| 31 | * $blog_id => [ |
||
| 32 | * $user_id => [ |
||
| 33 | * arrat of Jetpack_IXR_ClientMulticall |
||
| 34 | * ] |
||
| 35 | * ] |
||
| 36 | * ] |
||
| 37 | * |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | public static $clients = array(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Adds a new XMLRPC call to the queue to be processed on shutdown |
||
| 44 | * |
||
| 45 | * @param string $method The XML-RPC method. |
||
| 46 | * @param integer $user_id The user ID used to make the request (will use this user's token); Use 0 for the blog token. |
||
| 47 | * @param mixed ...$args This function accepts any number of additional arguments, that will be passed to the call. |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | public static function add_call( $method, $user_id = 0, ...$args ) { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Trigger the calls at shutdown |
||
| 78 | * |
||
| 79 | * @return void |
||
| 80 | */ |
||
| 81 | public static function do_calls() { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Trigger the calls when in a multi-site environment |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | private static function do_calls_multisite() { |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Trigger the calls in a single site environment |
||
| 121 | * |
||
| 122 | * @return void |
||
| 123 | */ |
||
| 124 | private static function do_calls_single_site() { |
||
| 139 | } |
||
| 140 |