Conditions | 12 |
Paths | 12 |
Total Lines | 57 |
Code Lines | 30 |
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 |
||
86 | $full_plugin_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin_path; |
||
87 | |||
88 | //Checking for file existence because some sync plugin module tests simulate plugin installation and deletion without putting file on disk |
||
89 | if ( file_exists( $full_plugin_path ) ) { |
||
90 | $all_plugin_data = get_plugin_data( $full_plugin_path ); |
||
91 | $data = array( |
||
92 | 'name' => $all_plugin_data['Name'], |
||
93 | 'version' => $all_plugin_data['Version'], |
||
94 | ); |
||
95 | } else { |
||
96 | $data = array( |
||
97 | 'name' => $plugin_path, |
||
98 | 'version' => 'unknown', |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | $this->plugin_info[ $plugin_path ] = $data; |
||
103 | } |
||
104 | |||
105 | public function deleted_plugin( $plugin_path, $is_deleted ) { |
||
106 | call_user_func( $this->action_handler, $plugin_path, $is_deleted, $this->plugin_info[ $plugin_path ] ); |
||
107 | unset( $this->plugin_info[ $plugin_path ] ); |
||
108 | } |
||
109 | |||
110 | public function expand_plugin_data( $args ) { |
||
111 | $plugin_path = $args[0]; |
||
112 | $plugin_data = array(); |
||
113 | |||
114 | if ( ! function_exists( 'get_plugins' ) ) { |
||
115 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
||
116 | } |
||
117 | $all_plugins = get_plugins(); |
||
118 | if ( isset( $all_plugins[ $plugin_path ] ) ) { |
||
119 | $all_plugin_data = $all_plugins[ $plugin_path ]; |
||
120 | $plugin_data['name'] = $all_plugin_data['Name']; |
||
121 | $plugin_data['version'] = $all_plugin_data['Version']; |
||
122 | } |
||
123 | |||
124 | return array( |
||
125 | $args[0], |
||
126 | $args[1], |
||
127 | $plugin_data, |
||
128 | ); |
||
129 | } |
||
130 | } |
||
131 |