| Conditions | 10 |
| Paths | 11 |
| Total Lines | 101 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 202 | public function wp_cli_customers_synchronize( $args, $assoc_args ) { |
||
| 203 | global $post; |
||
| 204 | global $wpdb; |
||
| 205 | |||
| 206 | $query = new \WP_Query( |
||
| 207 | array( |
||
| 208 | 'post_type' => 'pronamic_gateway', |
||
| 209 | 'post_status' => 'publish', |
||
| 210 | 'nopaging' => true, |
||
| 211 | 'meta_query' => array( |
||
| 212 | array( |
||
| 213 | 'key' => '_pronamic_gateway_id', |
||
| 214 | 'value' => 'mollie', |
||
| 215 | ), |
||
| 216 | array( |
||
| 217 | 'key' => '_pronamic_gateway_mollie_api_key', |
||
| 218 | 'compare' => 'EXISTS', |
||
| 219 | ), |
||
| 220 | ), |
||
| 221 | ) |
||
| 222 | ); |
||
| 223 | |||
| 224 | if ( $query->have_posts() ) { |
||
| 225 | while ( $query->have_posts() ) { |
||
| 226 | $query->the_post(); |
||
| 227 | |||
| 228 | $api_key = get_post_meta( $post->ID, '_pronamic_gateway_mollie_api_key', true ); |
||
| 229 | |||
| 230 | \WP_CLI::log( $post->post_title ); |
||
| 231 | \WP_CLI::log( $api_key ); |
||
| 232 | \WP_CLI::log( '' ); |
||
| 233 | |||
| 234 | $client = new Client( $api_key ); |
||
| 235 | |||
| 236 | $urls = array( |
||
| 237 | 'https://api.mollie.com/v2/customers?limit=250', |
||
| 238 | ); |
||
| 239 | |||
| 240 | $profile = $client->get_current_profile(); |
||
| 241 | |||
| 242 | $profile_id = $this->insert_or_update_profile( |
||
| 243 | $profile, |
||
| 244 | array( |
||
| 245 | 'api_key_live' => ( 'live_' === substr( $api_key, 0, 5 ) ) ? $api_key : null, |
||
| 246 | 'api_key_test' => ( 'test_' === substr( $api_key, 0, 5 ) ) ? $api_key : null, |
||
| 247 | ), |
||
| 248 | array( |
||
| 249 | 'api_key_live' => '%s', |
||
| 250 | 'api_key_test' => '%s', |
||
| 251 | ) |
||
| 252 | ); |
||
| 253 | |||
| 254 | while ( ! empty( $urls ) ) { |
||
| 255 | $url = array_shift( $urls ); |
||
| 256 | |||
| 257 | \WP_CLI::log( $url ); |
||
| 258 | |||
| 259 | $response = $client->send_request( $url ); |
||
| 260 | |||
| 261 | if ( isset( $response->count ) ) { |
||
| 262 | \WP_CLI::log( |
||
| 263 | \sprintf( |
||
| 264 | 'Found %d customer(s).', |
||
| 265 | $response->count |
||
| 266 | ) |
||
| 267 | ); |
||
| 268 | } |
||
| 269 | |||
| 270 | if ( isset( $response->_embedded->customers ) ) { |
||
| 271 | \WP_CLI\Utils\format_items( |
||
| 272 | 'table', |
||
| 273 | $response->_embedded->customers, |
||
| 274 | array( |
||
| 275 | 'id', |
||
| 276 | 'mode', |
||
| 277 | 'name', |
||
| 278 | 'email', |
||
| 279 | 'locale', |
||
| 280 | ) |
||
| 281 | ); |
||
| 282 | |||
| 283 | foreach ( $response->_embedded->customers as $object ) { |
||
| 284 | $customer_id = $this->insert_or_update_customer( |
||
| 285 | $object, |
||
| 286 | array( |
||
| 287 | 'profile_id' => $profile_id, |
||
| 288 | ), |
||
| 289 | array( |
||
| 290 | 'profile_id' => '%d', |
||
| 291 | ) |
||
| 292 | ); |
||
| 293 | } |
||
| 294 | } |
||
| 295 | |||
| 296 | if ( isset( $response->_links->next->href ) ) { |
||
| 297 | $urls[] = $response->_links->next->href; |
||
| 298 | } |
||
| 299 | } |
||
| 300 | } |
||
| 301 | |||
| 302 | \wp_reset_postdata(); |
||
| 303 | } |
||
| 353 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths