| Conditions | 7 |
| Paths | 13 |
| Total Lines | 54 |
| Code Lines | 26 |
| 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 |
||
| 38 | public function migrate_relationships() { |
||
| 39 | |||
| 40 | if ( true === $this->check_progress( __FUNCTION__ ) ) { |
||
| 41 | return '1'; |
||
| 42 | } |
||
| 43 | |||
| 44 | $migration_limit = (int) apply_filters( 'pods_upgrade_item_limit', 1500 ); |
||
| 45 | $migration_limit = max( $migration_limit, 100 ); |
||
| 46 | |||
| 47 | $last_id = (int) $this->check_progress( __FUNCTION__ ); |
||
| 48 | |||
| 49 | $relationship_fields = $this->api->load_fields( array( 'type' => array( 'pick', 'file' ) ) ); |
||
| 50 | |||
| 51 | foreach ( $relationship_fields as $field ) { |
||
| 52 | $pod = $this->api->load_pod( array( 'pod' => $field['pod'] ) ); |
||
| 53 | |||
| 54 | // Only target pods that are meta-enabled |
||
| 55 | if ( ! in_array( $pod['type'], array( 'post_type', 'media', 'user', 'comment' ), true ) ) { |
||
| 56 | continue; |
||
| 57 | } |
||
| 58 | |||
| 59 | // Only target multi-select relationships |
||
| 60 | $single_multi = pods_v( $field['type'] . '_format_type', $field['options'], 'single' ); |
||
| 61 | |||
| 62 | if ( 'multi' === $single_multi ) { |
||
| 63 | $limit = (int) pods_v( $field['type'] . '_limit', $field['options'], 0 ); |
||
| 64 | } else { |
||
| 65 | $limit = 1; |
||
| 66 | } |
||
| 67 | |||
| 68 | if ( $limit <= 1 ) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | |||
| 72 | // Get and loop through relationship meta |
||
| 73 | $sql = ' |
||
| 74 | |||
| 75 | '; |
||
| 76 | |||
| 77 | // if serialized (or array), save as individual meta items and save new order meta key |
||
| 78 | }//end foreach |
||
| 79 | |||
| 80 | $last_id = true; |
||
| 81 | |||
| 82 | $rel = array(); |
||
| 83 | |||
| 84 | $this->update_progress( __FUNCTION__, $last_id ); |
||
| 85 | |||
| 86 | if ( count( $rel ) === $migration_limit ) { |
||
| 87 | return '-2'; |
||
| 88 | } else { |
||
| 89 | return '1'; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 134 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.