Conditions | 4 |
Paths | 3 |
Total Lines | 51 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
35 | public function specials_single_schema() { |
||
36 | if ( is_singular( 'special' ) ) { |
||
37 | |||
38 | $destination_list_special = get_post_meta( get_the_ID(), 'destination_to_special', false ); |
||
39 | $destination_list_schema = array(); |
||
40 | $url_option = get_the_permalink(); |
||
41 | $special_title = get_the_title(); |
||
42 | $primary_url = get_the_permalink(); |
||
43 | $special_content = wp_strip_all_tags( get_the_content() ); |
||
44 | $thumb_url = get_the_post_thumbnail_url( get_the_ID(), 'full' ); |
||
45 | $price = get_post_meta( get_the_ID(), 'price', false ); |
||
46 | $start_validity = get_post_meta( get_the_ID(), 'booking_validity_start', false ); |
||
47 | $end_validity = get_post_meta( get_the_ID(), 'booking_validity_end', false ); |
||
48 | |||
49 | |||
50 | if ( ! empty( $destination_list_special ) ) { |
||
51 | foreach( $destination_list_special as $single_destination ) { |
||
52 | $url_option = get_the_permalink() . '#destination-' . $i; |
||
53 | $destination_name = get_the_title($single_destination); |
||
54 | $schema_day = array( |
||
55 | "@type" => "PostalAddress", |
||
56 | "addressLocality" => $destination_name, |
||
57 | ); |
||
58 | $destination_list_schema[] = $schema_day; |
||
59 | } |
||
60 | } |
||
61 | $meta = array( |
||
62 | array( |
||
63 | "@context" => "http://schema.org", |
||
64 | "@type" => array("Trip", "ProfessionalService", "Offer"), |
||
65 | "offers" => array( |
||
66 | "@type" => "Offer", |
||
67 | "price" => $price, |
||
68 | "availabilityStarts" => $start_validity, |
||
69 | "availabilityEnds" => $end_validity, |
||
70 | ), |
||
71 | "address" => $destination_list_schema, |
||
72 | "telephone" => "0216713090", |
||
73 | "priceRange" => $price, |
||
74 | "description" => $special_content, |
||
75 | "image" => $thumb_url, |
||
76 | "name" => $special_title, |
||
77 | "provider" => "Southern Destinations", |
||
78 | "url" => $primary_url, |
||
79 | ), |
||
80 | ); |
||
81 | $output = wp_json_encode( $meta, JSON_UNESCAPED_SLASHES ); |
||
82 | ?> |
||
83 | <script type="application/ld+json"> |
||
84 | <?php echo wp_kses_post( $output ); ?> |
||
85 | </script> |
||
86 | <?php |
||
92 |