| Conditions | 17 |
| Paths | 183 |
| Total Lines | 95 |
| Code Lines | 33 |
| Lines | 34 |
| Ratio | 35.79 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 34 | public function on_upgrader_completion( $upgrader, $details ) { |
||
| 35 | if ( ! isset( $details['type'] ) ) { |
||
| 36 | return; |
||
| 37 | } |
||
| 38 | if ( 'plugin' != $details['type'] ) { |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | |||
| 42 | if ( ! isset( $details['action'] ) ) { |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | |||
| 46 | $plugins = ( isset( $details['plugins'] ) ? $details['plugins'] : null ); |
||
| 47 | if ( empty( $plugins ) ) { |
||
| 48 | $plugins = ( isset( $details['plugin'] ) ? array( $details['plugin'] ) : null ); |
||
| 49 | } |
||
| 50 | |||
| 51 | // for plugin installer |
||
| 52 | if ( empty( $plugins ) && method_exists( $upgrader, 'plugin_info' ) ) { |
||
| 53 | $plugins = array( $upgrader->plugin_info() ); |
||
| 54 | } |
||
| 55 | |||
| 56 | if ( empty( $plugins ) ) { |
||
| 57 | return; // We shouldn't be here |
||
| 58 | } |
||
| 59 | |||
| 60 | switch ( $details['action'] ) { |
||
| 61 | case 'update': |
||
| 62 | $errors = $this->get_errors( $upgrader->skin ); |
||
| 63 | var_dump( $plugins ); |
||
|
|
|||
| 64 | View Code Duplication | if ( $errors ) { |
|
| 65 | foreach ( $plugins as $slug ) { |
||
| 66 | /** |
||
| 67 | * Sync that a plugin update failed |
||
| 68 | * |
||
| 69 | * @since 5.8.0 |
||
| 70 | * |
||
| 71 | * @module sync |
||
| 72 | * |
||
| 73 | * @param string $plugin, Plugin slug |
||
| 74 | * @param string Error code |
||
| 75 | * @param string Error message |
||
| 76 | */ |
||
| 77 | do_action( 'jetpack_plugin_update_failed', $this->get_plugin_info( $slug ), $errors['code'], $errors['message'] ); |
||
| 78 | } |
||
| 79 | return; |
||
| 80 | } |
||
| 81 | /** |
||
| 82 | * Sync that a plugin update |
||
| 83 | * |
||
| 84 | * @since 5.8.0 |
||
| 85 | * |
||
| 86 | * @module sync |
||
| 87 | * |
||
| 88 | * @param array() $plugin, Plugin Data |
||
| 89 | */ |
||
| 90 | do_action( 'jetpack_plugins_updated', array_map( array( $this, 'get_plugin_info' ), $plugins ) ); |
||
| 91 | break; |
||
| 92 | case 'install': |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 96 | if ( 'install' === $details['action'] ) { |
||
| 97 | $errors = $this->get_errors( $upgrader->skin ); |
||
| 98 | View Code Duplication | if ( $errors ) { |
|
| 99 | foreach ( $plugins as $slug ) { |
||
| 100 | /** |
||
| 101 | * Sync that a plugin update failed |
||
| 102 | * |
||
| 103 | * @since 5.8.0 |
||
| 104 | * |
||
| 105 | * @module sync |
||
| 106 | * |
||
| 107 | * @param string $plugin, Plugin slug |
||
| 108 | * @param string Error code |
||
| 109 | * @param string Error message |
||
| 110 | */ |
||
| 111 | do_action( 'jetpack_plugin_install_failed', $this->get_plugin_info( $slug ), $errors['code'], $errors['message'] ); |
||
| 112 | } |
||
| 113 | return; |
||
| 114 | } |
||
| 115 | /** |
||
| 116 | * Signals to the sync listener that a plugin was installed and a sync action |
||
| 117 | * reflecting the installation and the plugin info should be sent |
||
| 118 | * |
||
| 119 | * @since 5.8.0 |
||
| 120 | * |
||
| 121 | * @module sync |
||
| 122 | * |
||
| 123 | * @param array() $plugin, Plugin Data |
||
| 124 | */ |
||
| 125 | do_action( 'jetpack_plugin_installed', array_map( array( $this, 'get_plugin_info' ), $plugins ) ); |
||
| 126 | return; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 287 |