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 |
||
3 | class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module { |
||
4 | |||
5 | private $action_handler; |
||
6 | private $plugin_info = array(); |
||
7 | |||
8 | public function name() { |
||
11 | |||
12 | public function init_listeners( $callable ) { |
||
22 | |||
23 | public function init_before_send() { |
||
28 | |||
29 | public function check_upgrader( $upgrader, $details) { |
||
30 | |||
31 | View Code Duplication | if ( ! isset( $details['type'] ) || |
|
32 | 'plugin' !== $details['type'] || |
||
33 | is_wp_error( $upgrader->skin->result ) || |
||
34 | ! method_exists( $upgrader, 'plugin_info' ) |
||
35 | ) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | if ( 'install' === $details['action'] ) { |
||
40 | $plugin_path = $upgrader->plugin_info(); |
||
41 | $plugins = get_plugins(); |
||
42 | $plugin_info = $plugins[ $plugin_path ]; |
||
43 | |||
44 | /** |
||
45 | * Signals to the sync listener that a plugin was installed and a sync action |
||
46 | * reflecting the installation and the plugin info should be sent |
||
47 | * |
||
48 | * @since 4.9.0 |
||
49 | * |
||
50 | * @param string $plugin_path Path of plugin installed |
||
51 | * @param mixed $plugin_info Array of info describing plugin installed |
||
52 | */ |
||
53 | do_action( 'jetpack_installed_plugin', $plugin_path, $plugin_info ); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | public function delete_plugin( $plugin_path ) { |
||
76 | |||
77 | public function deleted_plugin( $plugin_path, $is_deleted ) { |
||
81 | |||
82 | public function expand_plugin_data( $args ) { |
||
99 | } |
||
100 |