Skip to content

fix: checks for zero value before retrieving objects#88

Merged
ictbeheer merged 1 commit into
mainfrom
fix/checks
May 5, 2026
Merged

fix: checks for zero value before retrieving objects#88
ictbeheer merged 1 commit into
mainfrom
fix/checks

Conversation

@ictbeheer
Copy link
Copy Markdown
Member

When the comment being retrieved is equal to the global $comment, the parent lookup for a comment without parent causes an infinite loop.

Copilot AI review requested due to automatic review settings May 4, 2026 17:51
@ictbeheer ictbeheer requested a review from a team as a code owner May 4, 2026 17:51
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Coverage report for commit: e94b948
File: coverage.xml

Cover ┌─────────────────────────┐ Freq.
   0% │ ███████████████████████ │ 75.0%
  10% │ ██░░░░░░░░░░░░░░░░░░░░░ │  6.3%
  20% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  30% │ ██░░░░░░░░░░░░░░░░░░░░░ │  6.3%
  40% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  50% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  60% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  70% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  80% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  90% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
 100% │ ████░░░░░░░░░░░░░░░░░░░ │ 12.5%
      └─────────────────────────┘
 *Legend:* █ = Current Distribution 
Summary - Lines: 9.89% | Methods: 7.27%
FilesLinesMethodsBranches
src/Attributes
   Meta.php--100.00%
   MetaPrefix.php--100.00%
   TaxonomyPrefix.php--100.00%
   Terms.php--100.00%
src
   CommentData.php--100.00%
   ImageData.php--100.00%
   PostData.php8.94%7.41%100.00%
   TermData.php--100.00%
   UserData.php--100.00%
src/Contracts
   PostDataInterface.php100.00%100.00%100.00%
src/Enums
   PostStatus.php--100.00%
src/Mappers
   PostPrefixMapper.php--100.00%
   UserPrefixMapper.php--100.00%
src/Normalizers
   WPPostNormalizer.php--100.00%
src/Providers
   DataServiceProvider.php100.00%100.00%100.00%
src/Traits
   HasMeta.php25.00%-100.00%

🤖 comment via lucassabreu/comment-coverage-clover

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an infinite-recursion edge case in CommentData::fromComment() caused by calling WordPress retrieval functions with a zero ID (notably get_comment(0) falling back to the global $comment), by guarding lookups with explicit non-zero checks.

Changes:

  • Add 0 !== (int) ... guards before attempting get_post() lookups for comment post IDs.
  • Add 0 !== (int) ... guards before attempting get_comment() lookups for comment parent IDs.
  • Add 0 !== (int) ... guards before attempting get_userdata() lookups for comment user IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/CommentData.php
return new static(
id: (int) $comment->comment_ID,
post: null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null,
post: 0 !== (int) $comment->comment_post_ID && null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null,
Comment thread src/CommentData.php
return new static(
id: (int) $comment->comment_ID,
post: null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null,
post: 0 !== (int) $comment->comment_post_ID && null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null,
Comment thread src/CommentData.php
Comment on lines +50 to +51
parent: 0 !== (int) $comment->comment_parent && null !== get_comment((int) $comment->comment_parent) ? CommentData::fromComment(get_comment((int) $comment->comment_parent)) : null,
user: 0 !== (int) $comment->user_id && false !== get_userdata((int) $comment->user_id) ? UserData::fromUser(get_userdata((int) $comment->user_id)) : null,
Comment thread src/CommentData.php
Comment on lines +50 to +51
parent: 0 !== (int) $comment->comment_parent && null !== get_comment((int) $comment->comment_parent) ? CommentData::fromComment(get_comment((int) $comment->comment_parent)) : null,
user: 0 !== (int) $comment->user_id && false !== get_userdata((int) $comment->user_id) ? UserData::fromUser(get_userdata((int) $comment->user_id)) : null,
@ictbeheer ictbeheer merged commit 2f97117 into main May 5, 2026
9 checks passed
@ictbeheer ictbeheer deleted the fix/checks branch May 5, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants