Conditions | 15 |
Paths | 56 |
Total Lines | 49 |
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 |
||
105 | function _scan_batch() { |
||
106 | $paths = get_option( '_vp_current_scan' ); |
||
107 | if ( empty( $paths ) || $this->_scan_clean_up( $paths ) ) |
||
108 | return false; |
||
109 | |||
110 | if ( ! is_array( $paths ) ) { |
||
111 | return false; |
||
112 | } |
||
113 | |||
114 | reset( $paths ); |
||
115 | |||
116 | $type = null; |
||
117 | $current = false; |
||
118 | foreach ( $paths as $type => $current ) { |
||
119 | break; |
||
120 | } |
||
121 | |||
122 | if ( !is_object( $current ) || empty( $current->last_dir ) ) |
||
123 | return $this->_scan_clean_up( $paths, $type ); |
||
124 | |||
125 | $default_batch_limit = 400; |
||
126 | if ( ! function_exists( 'set_time_limit' ) || ! @set_time_limit( 0 ) ) { |
||
127 | $default_batch_limit = 100; // avoid timeouts |
||
128 | } |
||
129 | |||
130 | $GLOBALS['vp_signatures'] = get_option( '_vp_signatures' ); |
||
131 | if ( empty( $GLOBALS['vp_signatures'] ) ) |
||
132 | return false; |
||
133 | |||
134 | $limit = get_option( '_vp_batch_file_size', $default_batch_limit ); |
||
135 | $files = $current->get_files( $limit ); |
||
136 | |||
137 | // No more files to scan. |
||
138 | if ( !$current->last_dir || count( $files ) < $limit ) |
||
139 | unset( $paths[$type] ); |
||
140 | |||
141 | update_option( '_vp_current_scan', $paths ); |
||
142 | $results = array(); |
||
143 | foreach ( $files as $file ) { |
||
144 | $verdict = vp_scan_file( $file ); |
||
145 | if ( !empty( $verdict ) ) |
||
146 | $results[$file] = array( 'hash' => @md5_file( $file ), 'verdict' => $verdict ); |
||
147 | } |
||
148 | |||
149 | if ( !empty( $results ) ) { |
||
150 | $vaultpress = VaultPress::init(); |
||
151 | $vaultpress->add_ping( 'security', array( 'suspicious_v2' => $results ) ); |
||
152 | } |
||
153 | } |
||
154 | |||
163 |