Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix attempts to count possible non-countable variables or usage of un…
Browse files Browse the repository at this point in the history
…defined variables (#11473)

* Fix attempts to count possible non-countable variables or usage of undefined variables

This fixes a few miscellaneous small problems where a possibly undefined variable was attempted to be accessed or a variable that wasn't necessarily countable was passed to `count()`

These were found by running Rector with rules specific to finding issues with php8.

* Fixing lint spacing issue
  • Loading branch information
prettyboymp authored Nov 8, 2023
1 parent da06862 commit 48c7b93
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/BlockTypes/ProductCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ function( $acc, $query ) {
*/
if (
! empty( $merged_query['post__in'] ) &&
is_array( $merged_query['post__in'] ) &&
count( $merged_query['post__in'] ) > count( array_unique( $merged_query['post__in'] ) )
) {
$merged_query['post__in'] = array_unique(
Expand Down
1 change: 1 addition & 0 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function( $acc, $query ) {
*/
if (
! empty( $merged_query['post__in'] ) &&
is_array( $merged_query['post__in'] ) &&
count( $merged_query['post__in'] ) > count( array_unique( $merged_query['post__in'] ) )
) {
$merged_query['post__in'] = array_unique(
Expand Down
13 changes: 3 additions & 10 deletions src/StoreApi/Schemas/V1/ProductReviewSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ public function get_properties() {
* @return array
*/
public function get_item_response( $review ) {
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$rating = get_comment_meta( $review->comment_ID, 'rating', true ) === '' ? null : (int) get_comment_meta( $review->comment_ID, 'rating', true );
$data = [
$rating = get_comment_meta( $review->comment_ID, 'rating', true ) === '' ? null : (int) get_comment_meta( $review->comment_ID, 'rating', true );
return [
'id' => (int) $review->comment_ID,
'date_created' => wc_rest_prepare_date_response( $review->comment_date ),
'formatted_date_created' => get_comment_date( 'F j, Y', $review->comment_ID ),
Expand All @@ -171,16 +170,10 @@ public function get_item_response( $review ) {
'product_permalink' => get_permalink( (int) $review->comment_post_ID ),
'product_image' => $this->image_attachment_schema->get_item_response( get_post_thumbnail_id( (int) $review->comment_post_ID ) ),
'reviewer' => $review->comment_author,
'review' => $review->comment_content,
'review' => wp_autop( $review->comment_content ),
'rating' => $rating,
'verified' => wc_review_is_from_verified_owner( $review->comment_ID ),
'reviewer_avatar_urls' => rest_get_avatar_urls( $review->comment_author_email ),
];

if ( 'view' === $context ) {
$data['review'] = wpautop( $data['review'] );
}

return $data;
}
}
2 changes: 1 addition & 1 deletion src/Templates/SingleProductTemplateCompatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private static function has_single_product_template_blocks( $parsed_blocks ) {
private static function group_blocks( $parsed_blocks ) {
return array_reduce(
$parsed_blocks,
function( $carry, $block ) {
function( array $carry, array $block ) {
if ( 'core/template-part' === $block['blockName'] ) {
$carry[] = array( $block );
return $carry;
Expand Down
2 changes: 1 addition & 1 deletion templates/notices/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
exit;
}

if ( ! $notices ) {
if ( empty( $notices ) || ! is_array( $notices ) ) {
return;
}

Expand Down

0 comments on commit 48c7b93

Please sign in to comment.