| Conditions | 11 |
| Paths | 2 |
| Total Lines | 137 |
| Code Lines | 84 |
| 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 |
||
| 69 | public function wp_cli_customers_synchronize( $args, $assoc_args ) { |
||
| 70 | global $post; |
||
| 71 | global $wpdb; |
||
| 72 | |||
| 73 | $query = new \WP_Query( |
||
| 74 | array( |
||
| 75 | 'post_type' => 'pronamic_gateway', |
||
| 76 | 'post_status' => 'publish', |
||
| 77 | 'nopaging' => true, |
||
| 78 | 'meta_query' => array( |
||
| 79 | array( |
||
| 80 | 'key' => '_pronamic_gateway_id', |
||
| 81 | 'value' => 'mollie', |
||
| 82 | ), |
||
| 83 | array( |
||
| 84 | 'key' => '_pronamic_gateway_mollie_api_key', |
||
| 85 | 'compare' => 'EXISTS', |
||
| 86 | ), |
||
| 87 | ), |
||
| 88 | ) |
||
| 89 | ); |
||
| 90 | |||
| 91 | if ( $query->have_posts() ) { |
||
| 92 | while ( $query->have_posts() ) { |
||
| 93 | $query->the_post(); |
||
| 94 | |||
| 95 | $api_key = get_post_meta( $post->ID, '_pronamic_gateway_mollie_api_key', true ); |
||
| 96 | |||
| 97 | \WP_CLI::log( $post->post_title ); |
||
| 98 | \WP_CLI::log( $api_key ); |
||
| 99 | \WP_CLI::log( '' ); |
||
| 100 | |||
| 101 | $client = new Client( $api_key ); |
||
| 102 | |||
| 103 | $urls = array( |
||
| 104 | 'https://api.mollie.com/v2/customers?limit=250', |
||
| 105 | ); |
||
| 106 | |||
| 107 | while ( ! empty( $urls ) ) { |
||
| 108 | $url = array_shift( $urls ); |
||
| 109 | |||
| 110 | \WP_CLI::log( $url ); |
||
| 111 | |||
| 112 | $response = $client->send_request( $url ); |
||
| 113 | |||
| 114 | if ( isset( $response->count ) ) { |
||
| 115 | \WP_CLI::log( |
||
| 116 | \sprintf( |
||
| 117 | 'Found %d customer(s).', |
||
| 118 | $response->count |
||
| 119 | ) |
||
| 120 | ); |
||
| 121 | } |
||
| 122 | |||
| 123 | if ( isset( $response->_embedded->customers ) ) { |
||
| 124 | \WP_CLI\Utils\format_items( |
||
| 125 | 'table', |
||
| 126 | $response->_embedded->customers, |
||
| 127 | array( |
||
| 128 | 'id', |
||
| 129 | 'mode', |
||
| 130 | 'name', |
||
| 131 | 'email', |
||
| 132 | 'locale', |
||
| 133 | ) |
||
| 134 | ); |
||
| 135 | |||
| 136 | foreach ( $response->_embedded->customers as $object ) { |
||
| 137 | $id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->pronamic_pay_mollie_customers WHERE mollie_id = %s", $object->id ) ); |
||
| 138 | |||
| 139 | $data = array( |
||
| 140 | 'test_mode' => ( 'test' === $object->mode ), |
||
| 141 | 'email' => $object->email, |
||
| 142 | 'name' => $object->name, |
||
| 143 | ); |
||
| 144 | |||
| 145 | $format = array( |
||
| 146 | 'test_mode' => '%d', |
||
| 147 | 'email' => '%s', |
||
| 148 | 'name' => '%s', |
||
| 149 | ); |
||
| 150 | |||
| 151 | if ( null === $id ) { |
||
| 152 | $data['mollie_id'] = $object->id; |
||
| 153 | $foramt['mollie_id'] = '%s'; |
||
| 154 | |||
| 155 | $result = $wpdb->insert( |
||
| 156 | $wpdb->pronamic_pay_mollie_customers, |
||
| 157 | $data, |
||
| 158 | $format |
||
| 159 | ); |
||
| 160 | |||
| 161 | if ( false === $result ) { |
||
| 162 | \WP_CLI::error( |
||
| 163 | sprintf( |
||
| 164 | 'Database error: %s.', |
||
| 165 | $wpdb->last_error |
||
| 166 | ) |
||
| 167 | ); |
||
| 168 | } |
||
| 169 | } else { |
||
| 170 | $result = $wpdb->update( |
||
| 171 | $wpdb->pronamic_pay_mollie_customers, |
||
| 172 | $data, |
||
| 173 | array( |
||
| 174 | 'id' => $id, |
||
| 175 | ), |
||
| 176 | $format, |
||
| 177 | array( |
||
| 178 | 'id' => '%d' |
||
| 179 | ) |
||
| 180 | ); |
||
| 181 | |||
| 182 | if ( false === $result ) { |
||
| 183 | \WP_CLI::error( |
||
| 184 | sprintf( |
||
| 185 | 'Database error: %s.', |
||
| 186 | $wpdb->last_error |
||
| 187 | ) |
||
| 188 | ); |
||
| 189 | } |
||
| 190 | |||
| 191 | $id = $wpdb->insert_id; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | if ( isset( $response->_links->next->href ) ) { |
||
| 197 | $urls[] = $response->_links->next->href; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | |||
| 202 | \wp_reset_postdata(); |
||
| 203 | } |
||
| 204 | |||
| 205 | \WP_CLI::error( 'Command not fully implemented yet.' ); |
||
| 206 | } |
||
| 255 |
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