| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code 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 |
||
| 68 | public function test_download_ips() { |
||
| 69 | $prod_download = new \WC_Product_Download(); |
||
| 70 | $prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' ); |
||
| 71 | $prod_download->set_id( 1 ); |
||
| 72 | |||
| 73 | $product = new \WC_Product_Simple(); |
||
| 74 | $product->set_name( 'Test Product' ); |
||
| 75 | $product->set_downloadable( 'yes' ); |
||
| 76 | $product->set_downloads( array( $prod_download ) ); |
||
| 77 | $product->set_regular_price( 25 ); |
||
| 78 | $product->save(); |
||
| 79 | |||
| 80 | $order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( 1, $product ); |
||
| 81 | $order->set_status( 'completed' ); |
||
| 82 | $order->set_total( 100 ); |
||
| 83 | $order->save(); |
||
| 84 | |||
| 85 | $download = new \WC_Customer_Download(); |
||
| 86 | $download->set_user_id( $this->user ); |
||
| 87 | $download->set_order_id( $order->get_id() ); |
||
| 88 | $download->set_product_id( $product->get_id() ); |
||
| 89 | $download->set_download_id( $prod_download->get_id() ); |
||
| 90 | $download->save(); |
||
| 91 | |||
| 92 | $object = new \WC_Customer_Download_Log(); |
||
| 93 | $object->set_permission_id( $download->get_id() ); |
||
| 94 | $object->set_user_id( $this->user ); |
||
| 95 | $object->set_user_ip_address( '1.2.3.4' ); |
||
| 96 | $id = $object->save(); |
||
| 97 | |||
| 98 | $object = new \WC_Customer_Download_Log(); |
||
| 99 | $object->set_permission_id( $download->get_id() ); |
||
| 100 | $object->set_user_id( $this->user ); |
||
| 101 | $object->set_user_ip_address( '54.2.1.3' ); |
||
| 102 | $id = $object->save(); |
||
| 103 | |||
| 104 | // Save a second log for the same IP -- only one result for this IP should be returned. |
||
| 105 | $object = new \WC_Customer_Download_Log(); |
||
| 106 | $object->set_permission_id( $download->get_id() ); |
||
| 107 | $object->set_user_id( $this->user ); |
||
| 108 | $object->set_user_ip_address( '54.2.1.3' ); |
||
| 109 | $id = $object->save(); |
||
| 110 | |||
| 111 | $object = new \WC_Customer_Download_Log(); |
||
| 112 | $object->set_permission_id( $download->get_id() ); |
||
| 113 | $object->set_user_id( $this->user ); |
||
| 114 | $object->set_user_ip_address( '54.5.1.7' ); |
||
| 115 | $id = $object->save(); |
||
| 116 | |||
| 117 | $request = new \WP_REST_Request( 'GET', $this->endpoint . '/download-ips' ); |
||
| 118 | $request->set_query_params( |
||
| 119 | array( |
||
| 120 | 'match' => '54', |
||
| 121 | ) |
||
| 122 | ); |
||
| 123 | |||
| 124 | $response = $this->server->dispatch( $request ); |
||
| 125 | $addresses = $response->get_data(); |
||
| 126 | |||
| 127 | $this->assertEquals( 200, $response->get_status() ); |
||
| 128 | $this->assertEquals( 2, count( $addresses ) ); |
||
| 129 | |||
| 130 | $this->assertEquals( '54.2.1.3', $addresses[0]['user_ip_address'] ); |
||
| 131 | $this->assertEquals( '54.5.1.7', $addresses[1]['user_ip_address'] ); |
||
| 132 | } |
||
| 134 |
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