| Conditions | 8 |
| Paths | 7 |
| Total Lines | 80 |
| Code Lines | 42 |
| 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 |
||
| 25 | public static function review_data_eraser( $email_address, $page ) { |
||
| 26 | global $wpdb; |
||
| 27 | |||
| 28 | $response = array( |
||
| 29 | 'items_removed' => false, |
||
| 30 | 'items_retained' => false, |
||
| 31 | 'messages' => array(), |
||
| 32 | 'done' => true, |
||
| 33 | ); |
||
| 34 | |||
| 35 | if ( empty( $email_address ) ) { |
||
| 36 | return $response; |
||
| 37 | } |
||
| 38 | |||
| 39 | $page = (int) $page; |
||
| 40 | $items_removed = false; |
||
| 41 | $items_retained = false; |
||
| 42 | |||
| 43 | $reviews = self::reviews_by_author( $email_address, $page ); |
||
| 44 | |||
| 45 | if ( empty( $reviews ) ) { |
||
| 46 | return $response; |
||
| 47 | } |
||
| 48 | |||
| 49 | $messages = array(); |
||
| 50 | |||
| 51 | foreach ( $reviews as $review ) { |
||
| 52 | $anonymized_review = array(); |
||
| 53 | $anonymized_review['user_id'] = 0; |
||
| 54 | $anonymized_review['rating_ip'] = wp_privacy_anonymize_data( 'ip', $review->rating_ip ); |
||
| 55 | |||
| 56 | $review_id = (int) $review->id; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Filters whether to anonymize the review. |
||
| 60 | * |
||
| 61 | * @since 1.6.26 |
||
| 62 | * |
||
| 63 | * @param bool|string Whether to apply the review anonymization (bool). |
||
| 64 | * Custom prevention message (string). Default true. |
||
| 65 | * @param object $review Review object. |
||
| 66 | * @param array $anonymized_review Anonymized review data. |
||
| 67 | */ |
||
| 68 | $anon_message = apply_filters( 'geodir_anonymize_post_review', true, $review, $anonymized_review ); |
||
| 69 | |||
| 70 | if ( true !== $anon_message ) { |
||
| 71 | if ( $anon_message && is_string( $anon_message ) ) { |
||
| 72 | $messages[] = esc_html( $anon_message ); |
||
| 73 | } else { |
||
| 74 | /* translators: %d: Review ID */ |
||
| 75 | $messages[] = sprintf( __( 'Review %d contains personal data but could not be anonymized.', 'geodirectory' ), $review_id ); |
||
| 76 | } |
||
| 77 | |||
| 78 | $items_retained = true; |
||
| 79 | |||
| 80 | continue; |
||
| 81 | } |
||
| 82 | |||
| 83 | $args = array( |
||
| 84 | 'id' => $review_id, |
||
| 85 | ); |
||
| 86 | |||
| 87 | $updated = $wpdb->update( GEODIR_REVIEW_TABLE, $anonymized_review, $args ); |
||
| 88 | |||
| 89 | if ( $updated ) { |
||
| 90 | $items_removed = true; |
||
| 91 | } else { |
||
| 92 | $items_retained = true; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | $done = count( $reviews ) < $number; |
||
|
|
|||
| 97 | |||
| 98 | return array( |
||
| 99 | 'items_removed' => $items_removed, |
||
| 100 | 'items_retained' => $items_retained, |
||
| 101 | 'messages' => $messages, |
||
| 102 | 'done' => $done, |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 131 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.