Conditions | 15 |
Paths | 111 |
Total Lines | 81 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
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 | $state = array( |
||
63 | 'is_autoupdate' => Jetpack_Constants::is_true( 'JETPACK_PLUGIN_AUTOUPDATE' ), |
||
64 | ); |
||
65 | $errors = $this->get_errors( $upgrader->skin ); |
||
66 | if ( $errors ) { |
||
67 | foreach ( $plugins as $slug ) { |
||
68 | /** |
||
69 | * Sync that a plugin update failed |
||
70 | * |
||
71 | * @since 5.8.0 |
||
72 | * |
||
73 | * @module sync |
||
74 | * |
||
75 | * @param string $plugin , Plugin slug |
||
76 | * @param string Error code |
||
77 | * @param string Error message |
||
78 | */ |
||
79 | do_action( 'jetpack_plugin_update_failed', $this->get_plugin_info( $slug ), $errors['code'], $errors['message'], $state ); |
||
80 | } |
||
81 | |||
82 | return; |
||
83 | } |
||
84 | /** |
||
85 | * Sync that a plugin update |
||
86 | * |
||
87 | * @since 5.8.0 |
||
88 | * |
||
89 | * @module sync |
||
90 | * |
||
91 | * @param array () $plugin, Plugin Data |
||
92 | */ |
||
93 | do_action( 'jetpack_plugins_updated', array_map( array( $this, 'get_plugin_info' ), $plugins ), $state ); |
||
94 | break; |
||
95 | case 'install': |
||
|
|||
96 | |||
97 | } |
||
98 | |||
99 | if ( 'install' === $details['action'] ) { |
||
100 | /** |
||
101 | * Signals to the sync listener that a plugin was installed and a sync action |
||
102 | * reflecting the installation and the plugin info should be sent |
||
103 | * |
||
104 | * @since 5.8.0 |
||
105 | * |
||
106 | * @module sync |
||
107 | * |
||
108 | * @param array () $plugin, Plugin Data |
||
109 | */ |
||
110 | do_action( 'jetpack_plugin_installed', array_map( array( $this, 'get_plugin_info' ), $plugins ) ); |
||
111 | |||
112 | return; |
||
113 | } |
||
114 | } |
||
115 | |||
273 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.