Skip to content

(feat): add commentdata#57

Open
ictbeheer wants to merge 5 commits intomainfrom
feat/comment
Open

(feat): add commentdata#57
ictbeheer wants to merge 5 commits intomainfrom
feat/comment

Conversation

@ictbeheer
Copy link
Copy Markdown
Member

@ictbeheer ictbeheer commented Aug 7, 2025

Introduce the CommentData class to encapsulate comment details and enhance the post functionality by adding methods for comment count and retrieving comments.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 7, 2025

Coverage report for commit: 98e8d79
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.96% | 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.php26.47%-100.00%

🤖 comment via lucassabreu/comment-coverage-clover

@ictbeheer ictbeheer force-pushed the feat/comment branch 2 times, most recently from d1e8b5a to 7da491d Compare September 1, 2025 13:12
@ictbeheer ictbeheer marked this pull request as ready for review February 3, 2026 14:55
@ictbeheer ictbeheer requested a review from a team as a code owner February 3, 2026 14:55
Copy link
Copy Markdown
Contributor

@YvetteNikolov YvetteNikolov left a comment

Choose a reason for hiding this comment

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

Nice! Mooie toevoeging.

Vergeet de README niet te updaten.

Copilot AI review requested due to automatic review settings April 2, 2026 08:54
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

Adds first-class comment support to the data layer by introducing a CommentData DTO and extending PostData with helpers to fetch a post’s comment count and approved comments.

Changes:

  • Added PostData::commentCount() to expose the WordPress comment count for a post.
  • Added PostData::comments() to retrieve approved comments for a post.
  • Introduced CommentData with a fromComment(WP_Comment) constructor-style factory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/PostData.php Adds comment count and comment retrieval helpers on PostData.
src/CommentData.php Introduces CommentData and a fromComment() factory to map WP_Comment into a data object.

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

src/PostData.php Outdated
Comment on lines +315 to +333
public function commentCount(): ?int
{
if (null === $this->id || ! post_type_supports($this->postType, 'comments')) {
return null;
}

return (int) get_comments_number($this->id);
}

/**
* @param array<string, mixed> $args
*
* @return Collection<int, CommentData>
*/
public function comments(array $args = []): Collection
{
if (null === $this->id || ! post_type_supports($this->postType, 'comments')) {
return collect();
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

New behavior was added for comment counting and comment retrieval, but there are no tests covering these methods. Since PostData already has Pest/WP_Mock coverage, please add tests for commentCount() (supported vs unsupported post types and null ID) and comments() (default args and empty return when unsupported/null ID).

Copilot uses AI. Check for mistakes.
postType: $post->post_type,
slug: $post->post_name,
thumbnail: get_post_thumbnail_id($post->ID) ? new ImageData(get_post_thumbnail_id($post->ID)) : null,
commentCount: (int) $post->comment_count,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is 'comment_count' er altijd? Zag dat je eerder nog een check deed of het post type comments ondersteunde?

post_type_supports($this->postType, 'comments')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ja, comment_count is een kolom in de wp_posts tabel. Maar misschien is het wel mooier om null te returnen voor post types die geen comments ondersteunen ipv 0

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.

5 participants