1 | <?php |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
2 | /** |
||||||
3 | * The Review Schema |
||||||
4 | * |
||||||
5 | * @package to-reviews |
||||||
6 | */ |
||||||
7 | |||||||
8 | /** |
||||||
9 | * Returns schema Review data. |
||||||
10 | * |
||||||
11 | * @since 10.2 |
||||||
12 | */ |
||||||
13 | class LSX_TO_Schema_Review extends LSX_TO_Schema_Graph_Piece { |
||||||
14 | |||||||
15 | /** |
||||||
16 | * Constructor. |
||||||
17 | * |
||||||
18 | * @param \WPSEO_Schema_Context $context A value object with context variables. |
||||||
19 | */ |
||||||
20 | public function __construct( WPSEO_Schema_Context $context ) { |
||||||
0 ignored issues
–
show
The type
WPSEO_Schema_Context was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
21 | $this->post_type = 'review'; |
||||||
22 | parent::__construct( $context ); |
||||||
23 | } |
||||||
0 ignored issues
–
show
|
|||||||
24 | |||||||
25 | /** |
||||||
26 | * Returns Review data. |
||||||
27 | * |
||||||
28 | * @return array $data Review data. |
||||||
29 | */ |
||||||
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 ); |
||||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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( |
||||||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 10 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||||||
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 ), |
||||||
0 ignored issues
–
show
It seems like
$review_author can also be of type false ; however, parameter $name of lsx\legacy\Schema_Utils::get_author_schema_id() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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, |
||||||
0 ignored issues
–
show
The type
WPSEO_Schema_IDs was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
58 | ), |
||||||
59 | 'reviewRating' => array( |
||||||
0 ignored issues
–
show
|
|||||||
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' ), |
||||||
0 ignored issues
–
show
It seems like
$tour_list can also be of type false ; however, parameter $items of lsx\legacy\Schema_Utils::get_item_reviewed() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
66 | 'itemReviewed' => \lsx\legacy\Schema_Utils::get_item_reviewed( $accom_list, 'Product' ), |
||||||
67 | ); |
||||||
68 | |||||||
69 | if ( $this->context->site_represents_reference ) { |
||||||
0 ignored issues
–
show
|
|||||||
70 | $data['publisher'] = $this->context->site_represents_reference; |
||||||
71 | } |
||||||
72 | |||||||
73 | if ( '' !== $date_of_visit_start && '' !== $date_of_visit_end ) { |
||||||
0 ignored issues
–
show
|
|||||||
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' ); |
||||||
0 ignored issues
–
show
'keywords' of type string is incompatible with the type array expected by parameter $data_key of LSX_TO_Schema_Graph_Piece::add_taxonomy_terms() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() 'post_tag' of type string is incompatible with the type array expected by parameter $taxonomy of LSX_TO_Schema_Graph_Piece::add_taxonomy_terms() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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 | } |
||||||
0 ignored issues
–
show
|
|||||||
84 | |||||||
85 | /** |
||||||
0 ignored issues
–
show
|
|||||||
86 | * Adds the Destinations attached to the review |
||||||
87 | * |
||||||
88 | * @param array $data Country / State data. |
||||||
89 | * |
||||||
90 | * @return array $data Country / State data. |
||||||
91 | */ |
||||||
92 | public function add_destinations( $data, $data_key = '' ) { |
||||||
93 | $places_array = array(); |
||||||
94 | $destinations = get_post_meta( $this->context->id, 'destination_to_' . $this->post_type, false ); |
||||||
95 | if ( ! empty( $destinations ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
96 | foreach ( $destinations as $destination_id ) { |
||||||
0 ignored issues
–
show
|
|||||||
97 | if ( '' !== $destination_id ) { |
||||||
0 ignored issues
–
show
|
|||||||
98 | if ( 0 === wp_get_post_parent_id( $destination_id ) || false === wp_get_post_parent_id( $destination_id ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
99 | $places_array = \lsx\legacy\Schema_Utils::add_place( $places_array, 'Country', $destination_id, $this->context ); |
||||||
100 | } else { |
||||||
101 | $places_array = \lsx\legacy\Schema_Utils::add_place( $places_array, 'State', $destination_id, $this->context ); |
||||||
102 | } |
||||||
103 | } |
||||||
104 | } |
||||||
105 | } |
||||||
0 ignored issues
–
show
|
|||||||
106 | if ( ! empty( $places_array ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
107 | $data['spatialCoverage'] = $places_array; |
||||||
108 | } |
||||||
0 ignored issues
–
show
|
|||||||
109 | return $data; |
||||||
110 | } |
||||||
0 ignored issues
–
show
|
|||||||
111 | } |
||||||
112 |