| Conditions | 4 |
| Paths | 4 |
| Total Lines | 53 |
| Code Lines | 42 |
| 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 |
||
| 30 | public function generate() { |
||
| 31 | $post = get_post( $this->context->id ); |
||
| 32 | $review_author = get_post_meta( $post->ID, 'reviewer_name', true ); |
||
| 33 | $review_email = get_post_meta( $post->ID, 'reviewer_email', true ); |
||
| 34 | $rating_value = get_post_meta( $post->ID, 'rating', true ); |
||
| 35 | $description = wp_strip_all_tags( get_the_content() ); |
||
| 36 | $tour_list = get_post_meta( get_the_ID(), 'tour_to_review', false ); |
||
| 37 | $accom_list = get_post_meta( get_the_ID(), 'accommodation_to_review', false ); |
||
| 38 | $comment_count = get_comment_count( $this->context->id ); |
||
| 39 | $review_author = get_post_meta( $post->ID, 'reviewer_name', true ); |
||
| 40 | $date_of_visit_start = get_post_meta( $post->ID, 'date_of_visit_start', true ); |
||
| 41 | $date_of_visit_end = get_post_meta( $post->ID, 'date_of_visit_end', true ); |
||
| 42 | |||
| 43 | $data = array( |
||
| 44 | '@type' => 'Review', |
||
| 45 | '@id' => $this->context->canonical . '#review', |
||
| 46 | 'author' => array( |
||
| 47 | '@type' => 'Person', |
||
| 48 | '@id' => \lsx\legacy\Schema_Utils::get_author_schema_id( $review_author, $review_email, $this->context ), |
||
| 49 | 'name' => $review_author, |
||
| 50 | 'email' => $review_email, |
||
| 51 | ), |
||
| 52 | 'headline' => get_the_title(), |
||
| 53 | 'datePublished' => mysql2date( DATE_W3C, $post->post_date_gmt, false ), |
||
| 54 | 'dateModified' => mysql2date( DATE_W3C, $post->post_modified_gmt, false ), |
||
| 55 | 'commentCount' => $comment_count['approved'], |
||
| 56 | 'mainEntityOfPage' => array( |
||
| 57 | '@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH, |
||
| 58 | ), |
||
| 59 | 'reviewRating' => array( |
||
| 60 | '@type' => 'Rating', |
||
| 61 | 'ratingValue' => $rating_value, |
||
| 62 | 'bestRating' => $rating_value, |
||
| 63 | ), |
||
| 64 | 'reviewBody' => $description, |
||
| 65 | 'itemReviewed' => \lsx\legacy\Schema_Utils::get_item_reviewed( $tour_list, 'Product' ), |
||
| 66 | 'itemReviewed' => \lsx\legacy\Schema_Utils::get_item_reviewed( $accom_list, 'Product' ), |
||
| 67 | ); |
||
| 68 | |||
| 69 | if ( $this->context->site_represents_reference ) { |
||
| 70 | $data['publisher'] = $this->context->site_represents_reference; |
||
| 71 | } |
||
| 72 | |||
| 73 | if ( '' !== $date_of_visit_start && '' !== $date_of_visit_end ) { |
||
| 74 | $data['temporalCoverage'] = $date_of_visit_start . ' - ' . $date_of_visit_end; |
||
| 75 | } |
||
| 76 | |||
| 77 | $data = \lsx\legacy\Schema_Utils::add_image( $data, $this->context ); |
||
| 78 | $data = $this->add_taxonomy_terms( $data, 'keywords', 'post_tag' ); |
||
| 79 | $data = $this->add_taxonomy_terms( $data, 'reviewSection', 'category' ); |
||
| 80 | $data = $this->add_offers( $data ); |
||
| 81 | $data = $this->add_destinations( $data ); |
||
| 82 | return $data; |
||
| 83 | } |
||
| 112 |