| Conditions | 10 |
| Paths | 11 |
| Total Lines | 103 |
| Code Lines | 63 |
| 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 |
||
| 73 | public function wp_cli_customers_synchronize( $args, $assoc_args ) { |
||
| 74 | global $post; |
||
| 75 | global $wpdb; |
||
| 76 | |||
| 77 | $query = new \WP_Query( |
||
| 78 | array( |
||
| 79 | 'post_type' => 'pronamic_gateway', |
||
| 80 | 'post_status' => 'publish', |
||
| 81 | 'nopaging' => true, |
||
| 82 | 'meta_query' => array( |
||
| 83 | array( |
||
| 84 | 'key' => '_pronamic_gateway_id', |
||
| 85 | 'value' => 'mollie', |
||
| 86 | ), |
||
| 87 | array( |
||
| 88 | 'key' => '_pronamic_gateway_mollie_api_key', |
||
| 89 | 'compare' => 'EXISTS', |
||
| 90 | ), |
||
| 91 | ), |
||
| 92 | ) |
||
| 93 | ); |
||
| 94 | |||
| 95 | if ( $query->have_posts() ) { |
||
| 96 | while ( $query->have_posts() ) { |
||
| 97 | $query->the_post(); |
||
| 98 | |||
| 99 | $api_key = get_post_meta( $post->ID, '_pronamic_gateway_mollie_api_key', true ); |
||
| 100 | |||
| 101 | \WP_CLI::log( $post->post_title ); |
||
| 102 | \WP_CLI::log( $api_key ); |
||
| 103 | \WP_CLI::log( '' ); |
||
| 104 | |||
| 105 | $client = new Client( $api_key ); |
||
| 106 | |||
| 107 | $urls = array( |
||
| 108 | 'https://api.mollie.com/v2/customers?limit=250', |
||
| 109 | ); |
||
| 110 | |||
| 111 | $profile = Profile::from_object( $client->get_current_profile() ); |
||
| 112 | |||
| 113 | $profile_id = $this->profile_data_store->save_profile( |
||
| 114 | $profile, |
||
| 115 | array( |
||
| 116 | 'api_key_live' => ( 'live_' === substr( $api_key, 0, 5 ) ) ? $api_key : null, |
||
| 117 | 'api_key_test' => ( 'test_' === substr( $api_key, 0, 5 ) ) ? $api_key : null, |
||
| 118 | ), |
||
| 119 | array( |
||
| 120 | 'api_key_live' => '%s', |
||
| 121 | 'api_key_test' => '%s', |
||
| 122 | ) |
||
| 123 | ); |
||
| 124 | |||
| 125 | while ( ! empty( $urls ) ) { |
||
| 126 | $url = array_shift( $urls ); |
||
| 127 | |||
| 128 | \WP_CLI::log( $url ); |
||
| 129 | |||
| 130 | $response = $client->send_request( $url ); |
||
| 131 | |||
| 132 | if ( isset( $response->count ) ) { |
||
| 133 | \WP_CLI::log( |
||
| 134 | \sprintf( |
||
| 135 | 'Found %d customer(s).', |
||
| 136 | $response->count |
||
| 137 | ) |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | if ( isset( $response->_embedded->customers ) ) { |
||
| 142 | \WP_CLI\Utils\format_items( |
||
| 143 | 'table', |
||
| 144 | $response->_embedded->customers, |
||
| 145 | array( |
||
| 146 | 'id', |
||
| 147 | 'mode', |
||
| 148 | 'name', |
||
| 149 | 'email', |
||
| 150 | 'locale', |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | |||
| 154 | foreach ( $response->_embedded->customers as $object ) { |
||
| 155 | $customer = Customer::from_object( $object ); |
||
| 156 | |||
| 157 | $customer_id = $this->customer_data_store->save_customer( |
||
| 158 | $customer, |
||
| 159 | array( |
||
| 160 | 'profile_id' => $profile_id, |
||
| 161 | ), |
||
| 162 | array( |
||
| 163 | 'profile_id' => '%d', |
||
| 164 | ) |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | if ( isset( $response->_links->next->href ) ) { |
||
| 170 | $urls[] = $response->_links->next->href; |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | \wp_reset_postdata(); |
||
| 176 | } |
||
| 227 |
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