| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 9 | public function testAddCustomFields() |
||
| 10 | { |
||
| 11 | $field = array( |
||
| 12 | 'listing_type' => 'gd_place', |
||
| 13 | 'data_type' => '', |
||
| 14 | 'field_type' => 'select', |
||
| 15 | 'admin_title' => __( 'Place Type', 'test' ), |
||
| 16 | 'admin_desc' => __( 'Select the place type.', 'test' ), |
||
| 17 | 'site_title' => __( 'Place Type', 'test' ), |
||
| 18 | 'htmlvar_name' => 'test_place_type', |
||
| 19 | 'default_value' => '', |
||
| 20 | 'option_values' => 'Hotel,Bar,Restaurant,Pub', |
||
| 21 | 'is_default' => '1', |
||
| 22 | 'is_admin' => '1', |
||
| 23 | 'clabels' => __( 'Place Type', 'test' ) |
||
| 24 | ); |
||
| 25 | |||
| 26 | $lastid = geodir_custom_field_save( $field ); |
||
| 27 | |||
| 28 | $this->assertTrue(is_int($lastid)); |
||
| 29 | |||
| 30 | |||
| 31 | $field2 = array( |
||
| 32 | 'listing_type' => 'gd_place', |
||
| 33 | 'data_type' => 'VARCHAR', |
||
| 34 | 'field_type' => 'url', |
||
| 35 | 'admin_title' => __( 'Website Link', 'test' ), |
||
| 36 | 'admin_desc' => __( 'Enter the website link.', 'test' ), |
||
| 37 | 'site_title' => __( 'Website Link', 'test' ), |
||
| 38 | 'htmlvar_name' => 'test_ws_link', |
||
| 39 | 'default_value' => '', |
||
| 40 | 'option_values' => '', |
||
| 41 | 'is_default' => '1', |
||
| 42 | 'is_admin' => '1', |
||
| 43 | 'clabels' => __( 'Website Link', 'test' ) |
||
| 44 | ); |
||
| 45 | |||
| 46 | $lastid2 = geodir_custom_field_save( $field2 ); |
||
| 47 | |||
| 48 | $this->assertTrue(is_int($lastid2)); |
||
| 49 | |||
| 50 | //test error |
||
| 51 | $field3 = array( |
||
| 52 | 'listing_type' => 'gd_place', |
||
| 53 | 'data_type' => '', |
||
| 54 | 'field_type' => 'select', |
||
| 55 | 'admin_title' => __( 'Place Type', 'test' ), |
||
| 56 | 'admin_desc' => __( 'Select the place type.', 'test' ), |
||
| 57 | 'site_title' => __( 'Place Type', 'test' ), |
||
| 58 | 'htmlvar_name' => 'test_place_type', |
||
| 59 | 'default_value' => '', |
||
| 60 | 'option_values' => 'Hotel,Bar,Restaurant,Pub', |
||
| 61 | 'is_default' => '1', |
||
| 62 | 'is_admin' => '1', |
||
| 63 | 'clabels' => __( 'Place Type', 'test' ) |
||
| 64 | ); |
||
| 65 | |||
| 66 | $error = geodir_custom_field_save( $field3 ); |
||
| 67 | |||
| 68 | $this->assertContains( 'HTML Variable Name should be a unique name', $error ); |
||
| 69 | } |
||
| 70 | |||
| 76 | ?> |
||
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.