Skip to content

Conversation

@JosephGabito
Copy link
Contributor

@JosephGabito JosephGabito commented Aug 4, 2025

What's changed

  • New method: isType(string $prefix): bool added to WordPress\AiClient\Files\ValueObjects\MimeType.
  • Refactor: isImage(), isAudio(), isVideo(), and isText() now delegate to isType() instead of repeating strpos() logic.
  • Tests: Added testIsType() to cover positive and negative cases; all existing tests remain green.

Why it matters

  • Keeps the convenient is*() helpers for common categories while introducing a general-purpose fallback for any non-enumerated MIME groups (e.g., fonts, scripts) without bloating the API.
  • Centralizes prefix matching, reducing duplication and clarifying intent.
  • Lays groundwork for future category checks with no breaking changes.
  • All tests including the new MimeTypeTest::testIsType() should pass.

Open to feedback, happy to adjust if we'd like any tweaks

Introduces a hasMimeType method to check if a MIME type starts with a given type, refactors isImage, isAudio, isVideo, and isText to use this new method, and adds corresponding unit tests.
Copy link
Member

@JasonTheAdams JasonTheAdams left a comment

Choose a reason for hiding this comment

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

Thanks, @JosephGabito! Added a suggestion.

Refactored the MimeType value object by renaming the hasMimeType method to isType for improved clarity. Updated all internal usages and corresponding unit tests to use the new method name.
Updated the isType method in MimeType to perform case-insensitive checks by converting the input to lowercase. Adjusted and expanded unit tests to verify case insensitivity and improved test coverage.
@JosephGabito JosephGabito changed the title Add hasMimeType() fallback method to MimeType value object Add isType() fallback method to MimeType value object Aug 4, 2025
Updated the PHPDoc for the isType method to clarify that it checks if the stored MIME type begins with the given prefix, improving documentation accuracy and developer understanding.
Copy link
Member

@JasonTheAdams JasonTheAdams left a comment

Choose a reason for hiding this comment

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

This is great! Nice improvement! Thank you!

@JosephGabito
Copy link
Contributor Author

@JasonTheAdams

Appreciate the fast review and the pointer on naming. Glad this helps tighten things up. 💪

@JasonTheAdams JasonTheAdams merged commit 9241e03 into WordPress:trunk Aug 4, 2025
4 checks passed
@felixarntz felixarntz added this to the Finish the foundation milestone Aug 13, 2025
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.

3 participants